Part Number Hot Search : 
20M10 008H24 LT1140CS A2918SW 239800P P6KE62CP D8749HD LT3684
Product Description
Full Text Search
 

To Download PIC18F4585-P Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2004 microchip technology inc. preliminary ds39625b pic18f2585/2680/4585/4680 data sheet 28/40/44-pin enhanced flash microcontrollers with ecan? technology, 10-bit a/d and nanowatt technology
ds39625b-page ii preliminary ? 2004 microchip technology inc. information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. it is your responsibility to ensure that your application m eets with your specifications. no representation or warranty is given and no liability is assumed by microchip technol ogy incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. use of mi crochip?s products as critical components in life support syst ems is not authorized except with express written approval by microchip. no licenses are conveyed, implicitly or ot herwise, under any intellectual property rights. trademarks the microchip name and logo, the microchip logo, accuron, dspic, k ee l oq , micro id , mplab, pic, picmicro, picstart, pro mate, powersmart, rfpic, and smartshunt are registered trademarks of micr ochip technology incorporated in the u.s.a. and other countries. amplab, filterlab, mxdev, mxlab, picmaster, seeval, smartsensor and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, app lication maestro, dspicdem, dspicdem.net, dspicworks, ecan, economonitor, fansense, flexrom, fuzzylab, in-circuit serial programming, icsp, icepic, migratable memory, mpasm, mplib, mplink, mpsim, pickit, picdem, picdem.net, piclab, pictail, powercal, powerinfo, powermate, powertool, rflab, rfpicdem, select mode, smart serial, smarttel and total endurance ar e trademarks of microchip technology incorporated in the u.s.a. and other countries. sqtp is a service mark of mi crochip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2004, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices:  microchip products meet the specification cont ained in their particular microchip data sheet.  microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions.  there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specif ications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property.  microchip is willing to work with the customer who is concerned about the integrity of their code.  neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona and mountain view, california in october 2003. the company?s quality system processes and procedures are for its picmicro ? 8-bit mcus, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
? 2004 microchip technology inc. preliminary ds39625b-page 1 pic18f2585/2680/4585/4680 power managed modes:  run: cpu on, peripherals on  idle: cpu off, peripherals on  sleep: cpu off, peripherals off  idle mode currents down to 5.8 a typical  sleep mode currents down to 0.1 a typical  timer1 oscillator: 1.1 a, 32 khz, 2v  watchdog timer: 2.1 a  two-speed oscillator start-up flexible oscillator structure:  four crystal modes, up to 40 mhz  4x phase lock loop (pll) ? available for crystal and internal oscillators  two external rc modes, up to 4 mhz  two external clock modes, up to 40 mhz  internal oscillator block: - 8 user selectable frequencies, from 31 khz to 8 mhz - provides a complete range of clock speeds, from 31 khz to 32 mhz when used with pll - user tunable to compensate for frequency drift  secondary oscillator using timer1 @ 32 khz  fail-safe clock monitor - allows for safe shutdown if peripheral clock stops special microcontroller features:  c compiler optimized architecture with optional extended instruction set  100,000 erase/write cycle enhanced flash program memory typical  1,000,000 erase/write cycle data eeprom memory typical  flash/data eeprom retention: > 40 years  self-programmable under software control  priority levels for interrupts  8 x 8 single cycle hardware multiplier  extended watchdog timer (wdt): - programmable period from 41 ms to 131s  single-supply 5v in-circuit serial programming? (icsp?) via two pins  in-circuit debug (icd) via two pins  wide operating voltage range: 2.0v to 5.5v peripheral highlights:  high current sink/source 25 ma/25 ma  three external interrupts  one capture/compare/pwm (ccp1) module  enhanced capture/compare/pwm (eccp1) module (40/44-pin devices only): - one, two or four pwm outputs - selectable polarity - programmable dead time - auto-shutdown and auto-restart  master synchronous serial port (mssp) module supporting 3-wire spi? (all 4 modes) and i 2 c? master and slave modes  enhanced addressable usart module: - supports rs-485, rs-232 and lin 1.3 - rs-232 operation using internal oscillator block (no external crystal required) - auto-wake-up on start bit - auto-baud detect  10-bit, up to 11-channel analog-to-digital converter module (a/d), up to 100 ksps - auto-acquisition capability - conversion available during sleep  dual analog comparators with input multiplexing ecan module features:  message bit rates up to 1 mbps  conforms to can 2.0b active specification  fully backward compatible with pic18xxx8 can modules  three modes of operation: - legacy, enhanced legacy, fifo  three dedicated transmit buffers with prioritization  two dedicated receive buffers  six programmable receive/transmit buffers  three full 29-bit acceptance masks  16 full 29-bit acceptance filters w/ dynamic association  devicenet? data byte filter support  automatic remote frame handling  advanced error management features device program memory data memory i/o 10-bit a/d (ch) ccp1/ eccp1 (pwm) mssp eusart comp. timers 8/16-bit flash (bytes) # single-word instructions sram (bytes) eeprom (bytes) spi? master i 2 c? pic18f2585 48k 24576 3328 1024 28 8 1/0 y y 1 0 1/3 pic18f2680 64k 32768 3328 1024 28 8 1/0 y y 1 0 1/3 pic18f4585 48k 24576 3328 1024 44 11 1/1 y y 1 2 1/3 pic18f4680 64k 32768 3328 1024 40/44 11 1/1 y y 1 2 1/3 28/40/44-pin enhanced flas h microcontrollers with ecan ? technology, 10-bit a/d and nanowatt technology
pic18f2585/2680/4585/4680 ds39625b-page 2 preliminary ? 2004 microchip technology inc. pin diagrams rb7/kbi3/pgd rb6/kbi2/pgc rb5/kbi1/pgm rb4/kbi0/an9 rb3/canrx rb2/int2/cantx rb1/int1/an8 rb0/int0/flt0/an10 v dd v ss rd7/psp7/p1d rd6/psp6/p1c rd5/psp5/p1b rd4/psp4/eccp1/p1a rc7/rx/dt rc6/tx/ck rc5/sdo rc4/sdi/sda rd3/psp3/c2in- rd2/psp2/c2in+ mclr /v pp /re3 ra0/an0/cv ref ra1/an1 ra2/an2/v ref - ra3/an3/v ref + ra4/t0cki ra5/an4/ss /hlvdin re0/rd /an5 re1/wr /an6/c1out re2/cs /an7/c2out v dd v ss osc1/clki/ra7 osc2/clko/ra6 rc0/t1oso/t13cki rc1/t1osi rc2/ccp1 rc3/sck/scl rd0/psp0/c1in+ rd1/psp1/c1in- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 pic18f4585 40-pin pdip pic18f4680 pic18f2585 10 11 2 3 4 5 6 1 8 7 9 12 13 14 15 16 17 18 19 20 23 24 25 26 27 28 22 21 mclr /v pp /re3 ra0/an0 ra1/an1 ra2/an2/v ref - ra3/an3/v ref + ra4/t0cki ra5/an4/ss /hlvdin v ss osc1/clki/ra7 osc2/clko/ra6 rc0/t1oso/t13cki rc1/t1osi rc2/ccp1 rc3/sck/scl rb7/kbi3/pgd rb6/kbi2/pgc rb5/kbi1/pgm rb4/kbi0/an9 rb3/canrx rb2/int2/cantx rb1/int1/an8 rb0/int0/an10 v dd v ss rc7/rx/dt rc6/tx/ck rc5/sdo rc4/sdi/sda 28-pin pdip, soic pic18f2680
? 2004 microchip technology inc. preliminary ds39625b-page 3 pic18f2585/2680/4585/4680 pin diagrams (continued) 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 38 8 7 44 43 42 41 40 39 16 17 29 30 31 32 33 23 24 25 26 27 28 36 34 35 9 pic18f4585 37 ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0/cv ref mclr /v pp /re3 nc rb7/kbi3/pgd rb6/kbi2/pgc rb5/kbi1/pgm rb4/kbi0/an9 nc rc6/tx/ck rc5/sdo rc4/sdi/sda rd3/psp3/c2in- rd2/psp2/c2in+ rd1/psp1/c1in- rd0/psp0/c1in+ rc3/sck/scl rc2/ccp1 rc1/t1osi nc nc rc0/t1oso/t13cki osc2/clko/ra6 osc1/clki/ra7 v ss v dd re2/cs /an7/c2out re1/wr /an6/c1out re0/rd /an5 ra5/an4/ss /hlvdin ra4/t0cki rc7/rx/dt rd4/psp4/eccp1/p1a rd5/psp5/p1b rd6/psp6/p1c v ss v dd rb0/int0/flt0/an10 rb1/int1/an8 rb2/int2/cantx rb3/canrx 44-pin tqfp rd7/psp7/p1d 5 4 44-pin qfn 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 38 8 7 44 43 42 41 40 39 16 17 29 30 31 32 33 23 24 25 26 27 28 36 34 35 9 pic18f4585 37 ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0/cv ref mclr /v pp /re3 rb7/kbi3/pgd rb6/kbi2/pgc rb5/kbi1/pgm rb4/kbi0/an9 nc rc6/tx/ck rc5/sdo rc4/sdi/sda rd3/psp3/c2in- rd2/psp2/c2in+ rd1/psp1/c1in- rd0/psp0/c1in+ rc3/sck/scl rc2/ccp1 rc1/t1osi rc0/t1oso/t13cki osc2/clko/ra6 osc1/clki/ra7 v ss av dd re2/cs /an7/c2out re1/wr /an6/c1out re0/rd /an5 ra5/an4/ss /hlvdin ra4/t0cki rc7/rx/dt rd5/psp5/p1b rd6/psp6/p1c v ss v dd rb0/int0/flt0/an10 rb1/int1/an8 rb2/int2/cantx rb3/canrx rd7/psp7/p1d 5 4 av ss v dd av dd pic18f4680 pic18f4680 rd4/psp4/eccp1/p1a
pic18f2585/2680/4585/4680 ds39625b-page 4 preliminary ? 2004 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ............................................................. 7 2.0 oscillator configurations ................................................................................................... ......................................................... 23 3.0 power managed modes ......................................................................................................... .................................................... 33 4.0 reset ....................................................................................................................... ................................................................... 41 5.0 memory organization ......................................................................................................... ........................................................ 61 6.0 flash program memory........................................................................................................ ...................................................... 95 7.0 data eeprom memory .......................................................................................................... ................................................. 105 8.0 8 x 8 hardware multiplier................................................................................................... ....................................................... 111 9.0 interrupts .................................................................................................................. ................................................................ 113 10.0 i/o ports .................................................................................................................. ................................................................. 129 11.0 timer0 module .............................................................................................................. ........................................................... 147 12.0 timer1 module .............................................................................................................. ........................................................... 151 13.0 timer2 module .............................................................................................................. ........................................................... 157 14.0 timer3 module .............................................................................................................. ........................................................... 159 15.0 capture/compare/pwm (ccp1) modules ......................................................................................... ...................................... 163 16.0 enhanced capture/compare/pwm (eccp1) module................................................................................ .............................. 173 17.0 master synchronous serial port (mssp) module ............................................................................... ..................................... 187 18.0 enhanced universal synchronous receiver tr ansmitter (eusart) ............................................................... ........................ 227 19.0 10-bit analog-to-digital converter (a/d) module ............................................................................ ......................................... 247 20.0 comparator module.......................................................................................................... ........................................................ 257 21.0 comparator voltage reference module ........................................................................................ ........................................... 263 22.0 high/low-voltage detect (hlvd)............................................................................................. ................................................ 267 23.0 ecan? module ............................................................................................................... ........................................................ 273 24.0 special features of the cpu ................................................................................................ .................................................... 343 25.0 instruction set summary .................................................................................................... ...................................................... 361 26.0 development support........................................................................................................ ....................................................... 411 27.0 electrical characteristics ................................................................................................. ......................................................... 417 28.0 dc and ac characteristics graphs and tables ................................................................................ ....................................... 453 29.0 packaging information...................................................................................................... ........................................................ 455 appendix a: revision history................................................................................................... .......................................................... 463 appendix b: device differences................................................................................................. ........................................................ 463 appendix c: conversion considerations .......................................................................................... ................................................. 464 appendix d: migration from baseline to enhanced devices........................................................................ ..................................... 464 appendix e: migration from mid-range to enhanced devices ....................................................................... ................................... 465 appendix f: migration from high-end to enhanced devices ........................................................................ ..................................... 465 index .......................................................................................................................... ........................................................................ 467 on-line support................................................................................................................ ................................................................. 479 systems information and upgrade hot line ....................................................................................... ............................................... 479 reader response ................................................................................................................ .............................................................. 480 pic18f2585/2680/4585/4680 product identification system ........................................................................ .................................... 481
? 2004 microchip technology inc. preliminary ds39625b-page 5 pic18f2585/2680/4585/4680 to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@mail.microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/doc umentation issues become known to us, we will publis h an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particul ar device, please check with one of the following:  microchip?s worldwide web site; http://www.microchip.com  your local microchip sales office (see last page)  the microchip corporate literatu re center; u.s. fax: (480) 792-7277 when contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (inclu de literature number) you are using. customer notification system register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
pic18f2585/2680/4585/4680 ds39625b-page 6 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 7 pic18f2585/2680/4585/4680 1.0 device overview this document contains device specific information for the following devices:  pic18f2585  pic18f2680  pic18f4585  pic18f4680 this family of devices offers the advantages of all pic18 microcontrollers ? namely, high computational performance at an economical price ? with the addition of high-endurance, enhanced flash program memory. in addition to these features, the pic18f2585/2680/4585/4680 family introduces design enhancements that make these microcontrollers a logical choice for many high-performance, power sensitive applications. 1.1 new core features 1.1.1 nanowatt technology all of the devices in the pic18f2585/2680/4585/4680 family incorporate a range of features that can signifi- cantly reduce power consumption during operation. key items include:  alternate run modes: by clocking the controller from the timer1 source or the internal oscillator block, power consumption during code execution can be reduced by as much as 90%.  multiple idle modes: the controller can also run with its cpu core disabled but the peripherals still active. in these states, power consumption can be reduced even further, to as little as 4% of normal operation requirements.  on-the-fly mode switching: the power managed modes are invoked by user code during operation, allowing the user to incorporate power-saving ideas into their application?s software design.  lower consumption in key modules: the power requirements for both timer1 and the watchdog timer have been reduced by up to 80%, with typical values of 1.1 and 2.1 a, respectively.  extended instruction set: in addition to the standard 75 instructions of the pic18 instruction set, pic18f2585/2680/4585/4680 devices also provide an optional extension to the core cpu functionality. the added features include eight additional instructions that augment indirect and indexed addressing operations and the implementation of indexed literal offset addressing mode for many of the standard pic18 instructions. 1.1.2 multiple oscillator options and features all of the devices in the pic18f2585/2680/4585/4680 family offer ten different oscillator options, allowing users a wide range of choices in developing application hardware. these include:  four crystal modes, using crystals or ceramic resonators  two external clock modes, offering the option of using two pins (oscillator input and a divide-by-4 clock output) or one pin (oscillator input, with the second pin reassigned as general i/o)  two external rc oscillator modes with the same pin options as the external clock modes  an internal oscillator block which provides an 8 mhz clock (2% accuracy) and an intrc source (approximately 31 khz, stable over temperature and v dd ), as well as a range of 6 user selectable clock frequencies, between 125 khz to 4 mhz, for a total of 8 clock frequencies. this option frees the two oscillator pins for use as additional general purpose i/o.  a phase lock loop (pll) frequency multiplier, available to both the high-speed crystal and internal oscillator modes, which allows clock speeds of up to 40 mhz. used with the internal oscillator, the pll gives users a complete selection of clock speeds, from 31 khz to 32 mhz ? all without using an external crystal or clock circuit. besides its availability as a clock source, the internal oscillator block provides a stable reference source that gives the family additional features for robust operation:  fail-safe clock monitor: this option constantly monitors the main clock source against a refer- ence signal provided by the internal oscillator. if a clock failure occurs, the controller is switched to the internal oscillator block, allowing for continued low-speed operation or a safe application shutdown.  two-speed start-up: this option allows the internal oscillator to serve as the clock source from power-on reset, or wake-up from sleep mode, until the primary clock source is available.
pic18f2585/2680/4585/4680 ds39625b-page 8 preliminary ? 2004 microchip technology inc. 1.2 other special features  memory endurance: the enhanced flash cells for both program memory and data eeprom are rated to last for many thousands of erase/write cycles ? up to 100,000 for program memory and 1,000,000 for eeprom. data retention without refresh is conservatively estimated to be greater than 40 years.  self-programmability: these devices can write to their own program memory spaces under inter- nal software control. by using a bootloader routine located in the protected boot block at the top of program memory, it becomes possible to create an application that can update itself in the field.  extended instruction set: the pic18f2585/2680/4585/4680 family introduces an optional extension to the pic18 instruction set, which adds 8 new instructions and an indexed addressing mode. this extension, enabled as a device configuration option, has been specifically designed to optimize re-entrant application code originally developed in high-level languages, such as c.  enhanced ccp1 module: in pwm mode, this module provides 1, 2 or 4 modulated outputs for controlling half-bridge and full-bridge drivers. other features include auto-shutdown, for disabling pwm outputs on interrupt or other select conditions and auto-restart, to reactivate outputs once the condition has cleared.  enhanced addressable usart: this serial communication module is capable of standard rs-232 operation and provides support for the lin bus protocol. other enhancements include automatic baud rate detection and a 16-bit baud rate generator for improved resolution. when the microcontroller is using the internal oscillator block, the eusart provides stable operation for applications that talk to the outside world without using an external crystal (or its accompanying power requirement).  10-bit a/d converter: this module incorporates programmable acquisition time, allowing for a channel to be selected and a conversion to be initiated without waiting for a sampling period and thus, reduce code overhead.  extended watchdog timer (wdt): this enhanced version incorporates a 16-bit prescaler, allowing a time-out range from 4 ms to over 131 seconds, that is stable across operating voltage and temperature. 1.3 details on individual family members devices in the pic18f2585/2680/4585/4680 family are available in 28-pin (pic18f2x8x) and 40/44-pin (pic18f4x8x) packages. block diagrams for the two groups are shown in figure 1-1 and figure 1-2. the devices are differentiated from each other in six ways: 1. flash program memory (48 kbytes for pic18fx585 devices, 64 kbytes for pic18fx680). 2. a/d channels (8 for pic18f2x8x devices, 11 for pic18f4x8x devices). 3. i/o ports (3 bidirectional ports and 1 input only port on pic18f2x8x devices, 5 bidirectional ports on pic18f4x8x devices). 4. ccp1 and enhanced ccp1 implementation (pic18f2x8x devices have 1 standard ccp1 module, pic18f4x8x devices have one standard ccp1 module and one eccp1 module). 5. parallel slave port (present only on pic18f4x8x devices). 6. pic18f4x8x devices provide two comparators. all other features for devices in this family are identical. these are summarized in table 1-1. the pinouts for all devices are listed in table 1-2 and table 1-3. like all microchip pic18 devices, members of the pic18f2585/2680/4585/4680 family are available as both standard and low-voltage devices. standard devices with enhanced flash memory, designated with an ?f? in the part number (such as pic18 f 2585), accommodate an operating v dd range of 4.2v to 5.5v. low-voltage parts, designated by ?lf? (such as pic18 lf 2585), function over an extended v dd range of 2.0v to 5.5v.
? 2004 microchip technology inc. preliminary ds39625b-page 9 pic18f2585/2680/4585/4680 table 1-1: device features features pic18f2585 pic18f2680 pic18f4585 pic18f4680 operating frequency dc ? 40 mhz dc ? 40 mhz dc ? 40 mhz dc ? 40 mhz program memory (bytes) 49152 65536 49152 65536 program memory (instructions) 24576 32768 24576 32768 data memory (bytes) 3328 3328 3328 3328 data eeprom memory (bytes) 1024 1024 1024 1024 interrupt sources 19 19 20 20 i/o ports ports a, b, c, (e) ports a, b, c, (e) ports a, b, c, d, e ports a, b, c, d, e timers 4 4 4 4 capture/compare/pwm modules 1 1 1 1 enhanced capture/ compare/pwm modules 0011 ecan module 1 1 1 1 serial communications mssp, enhanced usart mssp, enhanced usart mssp, enhanced usart mssp, enhanced usart parallel communications (psp) no no yes yes 10-bit analog-to-digital module 8 input channels 8 input channels 11 input channels 11 input channels comparators 0 0 2 2 resets (and delays) por, bor, reset instruction, stack full, stack underflow (pwrt, ost), mclr (optional), wdt por, bor, reset instruction, stack full, stack underflow (pwrt, ost), mclr (optional), wdt por, bor, reset instruction, stack full, stack underflow (pwrt, ost), mclr (optional), wdt por, bor, reset instruction, stack full, stack underflow (pwrt, ost), mclr (optional), wdt programmable high/low-voltage detect yes yes yes yes programmable brown-out reset yes yes yes yes instruction set 75 instructions; 83 with extended instruction set enabled 75 instructions; 83 with extended instruction set enabled 75 instructions; 83 with extended instruction set enabled 75 instructions; 83 with extended instruction set enabled packages 28-pin pdip 28-pin soic 28-pin pdip 28-pin soic 40-pin pdip 44-pin qfn 44-pin tqfp 40-pin pdip 44-pin qfn 44-pin tqfp
pic18f2585/2680/4585/4680 ds39625b-page 10 preliminary ? 2004 microchip technology inc. figure 1-1: pic18f2585/2680 (28-pin) block diagram instruction decode & control porta portb portc ra4/t0cki ra5/an4/ss /hlvdin rb0/int0/an10 rc0/t1oso/t13cki rc1/t1osi rc2/ccp1 rc3/sck/scl rc4/sdi/sda rc5/sdo rc6/tx/ck rc7/rx/dt ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 rb1/int1/an8 data latch data memory (3.9 kbytes) address latch data address<12> 12 access bsr 44 pch pcl pclath 8 31 level stack program counter prodl prodh 8 x 8 multiply 8 8 8 alu<8> address latch program memory (48/64 kbytes) data latch 20 8 8 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 ir 12 3 rom latch rb2/int2/cantx rb3/canrx pclatu pcu porte mclr /v pp /re3 (1) osc2/clko/ra6 note 1: re3 is multiplexed with mclr and is only available when the mclr resets are disabled. 2: osc1/clki and osc2/clko are only available in select oscillator modes and when these pins are not being used as digital i/o. refer to section 2.0 ?oscillator configurations? for additional information. rb4/kbi0/an9 rb5/kbi1/pgm rb6/kbi2/pgc rb7/kbi3/pgd eusart comparator mssp 10-bit adc timer2 timer1 timer3 timer0 eccp1 hlvd ccp1 bor data eeprom w instruction bus <16> stkptr bank 8 state machine control signals 8 8 power-up timer oscillator start-up timer power-on reset watchdog timer osc1 (2) osc2 (2) v dd , brown-out reset internal oscillator fail-safe clock monitor reference band gap v ss mclr (1) block intrc oscillator 8 mhz oscillator single-supply programming in-circuit debugger t1osi t1oso osc1/clki/ra7 ecan bitop fsr0 fsr1 fsr2 inc/dec address 12 decode logic
? 2004 microchip technology inc. preliminary ds39625b-page 11 pic18f2585/2680/4585/4680 figure 1-2: pic18f4585/4680 (40/44-pin) block diagram instruction decode & control data latch data memory (3.9 kbytes) address latch data address<12> 12 access bsr 44 pch pcl pclath 8 31 level stack program counter prodl prodh 8 x 8 multiply 8 bitop 8 8 alu<8> address latch program memory (48/64 kbytes) data latch 20 8 8 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 ir 12 3 rom latch portd rd0/psp0 pclatu pcu porte mclr /v pp /re3 (1) re2/cs /an7/c2out re0/rd /an5 re1/wr /an6/c1out note 1: re3 is multiplexed with mclr and is only available when the mclr resets are disabled. 2: osc1/clki and osc2/clko are only available in select oscillator modes and when these pins are not being used as digital i/o. refer to section 2.0 ?oscillator configurations? for additional information. /c1in+ eusart comparator mssp 10-bit adc timer2 timer1 timer3 timer0 ccp1 hlvd eccp1 bor data eeprom w instruction bus <16> stkptr bank 8 state machine control signals 8 8 power-up timer oscillator start-up timer power-on reset watchdog timer osc1 (2) osc2 (2) v dd , brown-out reset internal oscillator fail-safe clock monitor reference band gap v ss mclr (1) block intrc oscillator 8 mhz oscillator single-supply programming in-circuit debugger t1osi t1oso rd1/psp1/c1in- rd2/psp2/c2in+ rd3/psp3/c2in- porta portb portc ra4/t0cki ra5/an4/ss /hlvdin rb0/int0/flt0/an10 rc0/t1oso/t13cki rc1/t1osi rc2/ccp1 rc3/sck/scl rc4/sdi/sda rc5/sdo rc6/tx/ck rc7/rx/dt ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0/cv ref rb1/int1/an8 rb2/int2/cantx rb3/canrx osc2/clko/ra6 rb4/kbi0/an9 rb5/kbi1/pgm rb6/kbi2/pgc rb7/kbi3/pgd osc1/clki/ra7 ecan fsr0 fsr1 fsr2 inc/dec address 12 decode logic rd4/psp4/eccp1/p1a rd5/psp5/p1b rd6/psp6/p1c rd7/psp7/p1d
pic18f2585/2680/4585/4680 ds39625b-page 12 preliminary ? 2004 microchip technology inc. table 1-2: pic18f2585/2680 pinout i/o descriptions pin name pin number pin type buffer type description pdip, soic mclr /v pp /re3 mclr v pp re3 1 i p i st st master clear (input) or programming voltage (input). master clear (reset) input. this pin is an active-low reset to the device. programming voltage input. digital input. osc1/clki/ra7 osc1 clki ra7 9 i i i/o st cmos ttl oscillator crystal or external clock input. oscillator crystal input or external clock source input. st buffer when configured in rc mode; cmos otherwise. external clock source input. always associated with pin function osc1. (see related os c1/clki, osc2/clko pins.) general purpose i/o pin. osc2/clko/ra6 osc2 clko ra6 10 o o i/o ? ? ttl oscillator crystal or clock output. oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. in rc mode, osc2 pin outputs clko which has 1/4 the frequency of osc1 and denotes the instruction cycle rate. general purpose i/o pin. legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power
? 2004 microchip technology inc. preliminary ds39625b-page 13 pic18f2585/2680/4585/4680 porta is a bidirectional i/o port. ra0/an0 ra0 an0 2 i/o i ttl analog digital i/o. analog input 0. ra1/an1 ra1 an1 3 i/o i ttl analog digital i/o. analog input 1. ra2/an2/v ref - ra2 an2 v ref - 4 i/o i i ttl analog analog digital i/o. analog input 2. a/d reference voltage (low) input. ra3/an3/v ref + ra3 an3 v ref + 5 i/o i i ttl analog analog digital i/o. analog input 3. a/d reference voltage (high) input. ra4/t0cki ra4 t0cki 6 i/o i ttl st digital i/o. timer0 external clock input. ra5/an4/ss /hlvdin ra5 an4 ss hlvdin 7 i/o i i i ttl analog ttl analog digital i/o. analog input 4. spi? slave select input. high/low-voltage detect input. ra6 see the osc2/clko/ra6 pin. ra7 see the osc1/clki/ra7 pin. table 1-2: pic18f2585/2680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip, soic legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power
pic18f2585/2680/4585/4680 ds39625b-page 14 preliminary ? 2004 microchip technology inc. portb is a bidirectional i/o port. portb can be software programmed for internal weak pull-ups on all inputs. rb0/int0/an10 rb0 int0 an10 21 i/o i i ttl st analog digital i/o. external interrupt 0. analog input 10. rb1/int1/an8 rb1 int1 an8 22 i/o i i ttl st analog digital i/o. external interrupt 1. analog input 8. rb2/int2/cantx rb2 int2 cantx 23 i/o i o ttl st ttl digital i/o. external interrupt 2. can bus tx. rb3/canrx rb3 canrx 24 i/o i ttl ttl digital i/o. can bus rx. rb4/kbi0/an9 rb4 kbi0 an9 25 i/o i i ttl ttl analog digital i/o. interrupt-on-change pin. analog input 9. rb5/kbi1/pgm rb5 kbi1 pgm 26 i/o i i/o ttl ttl st digital i/o. interrupt-on-change pin. low-voltage icsp? programming enable pin. rb6/kbi2/pgc rb6 kbi2 pgc 27 i/o i i/o ttl ttl st digital i/o. interrupt-on-change pin. in-circuit debugger and icsp programming clock pin. rb7/kbi3/pgd rb7 kbi3 pgd 28 i/o i i/o ttl ttl st digital i/o. interrupt-on-change pin. in-circuit debugger and icsp programming data pin. table 1-2: pic18f2585/2680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip, soic legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power
? 2004 microchip technology inc. preliminary ds39625b-page 15 pic18f2585/2680/4585/4680 portc is a bidirectional i/o port. rc0/t1oso/t13cki rc0 t1oso t13cki 11 i/o o i st ? st digital i/o. timer1 oscillator output. timer1/timer3 external clock input. rc1/t1osi rc1 t1osi 12 i/o i st cmos digital i/o. timer1 oscillator input. rc2/ccp1 rc2 ccp1 13 i/o i/o st st digital i/o. capture1 input/compare1 output/pwm1 output. rc3/sck/scl rc3 sck scl 14 i/o i/o i/o st st st digital i/o. synchronous serial clock input/output for spi? mode. synchronous serial clock input/output for i 2 c? mode. rc4/sdi/sda rc4 sdi sda 15 i/o i i/o st st st digital i/o. spi data in. i 2 c data i/o. rc5/sdo rc5 sdo 16 i/o o st ? digital i/o. spi data out. rc6/tx/ck rc6 tx ck 17 i/o o i/o st ? st digital i/o. eusart asynchronous transmit. eusart synchronous clock (see related rx/dt). rc7/rx/dt rc7 rx dt 18 i/o i i/o st st st digital i/o. eusart asynchronous receive. eusart synchronous data (see related tx/ck). re3 ? ? ? see mclr /v pp /re3 pin. v ss 8, 19 p ? ground reference for logic and i/o pins. v dd 20 p ? positive supply for logic and i/o pins. table 1-2: pic18f2585/2680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip, soic legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power
pic18f2585/2680/4585/4680 ds39625b-page 16 preliminary ? 2004 microchip technology inc. table 1-3: pic18f4585/4680 pinout i/o descriptions pin name pin number pin type buffer type description pdip qfn tqfp mclr /v pp /re3 mclr v pp re3 11818 i p i st st master clear (input) or programming voltage (input). master clear (reset) input. this pin is an active-low reset to the device. programming voltage input. digital input. osc1/clki/ra7 osc1 clki ra7 13 32 30 i i i/o st cmos ttl oscillator crystal or external clock input. oscillator crystal input or external clock source input. st buffer when configured in rc mode; cmos otherwise. external clock source input. always associated with pin function osc1. (see related osc1/clki, osc2/clko pins.) general purpose i/o pin. osc2/clko/ra6 osc2 clko ra6 14 33 31 o o i/o ? ? ttl oscillator crystal or clock output. oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. in rc mode, osc2 pin outputs clko which has 1/4 the frequency of osc1 and denotes the instruction cycle rate. general purpose i/o pin. legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power
? 2004 microchip technology inc. preliminary ds39625b-page 17 pic18f2585/2680/4585/4680 porta is a bidirectional i/o port. ra0/an0/cv ref ra0 an0 cv ref 21919 i/o i o ttl analog analog digital i/o. analog input 0. analog comparator reference output. ra1/an1 ra1 an1 32020 i/o i ttl analog digital i/o. analog input 1. ra2/an2/v ref - ra2 an2 v ref - 42121 i/o i i ttl analog analog digital i/o. analog input 2. a/d reference voltage (low) input. ra3/an3/v ref + ra3 an3 v ref + 52222 i/o i i ttl analog analog digital i/o. analog input 3. a/d reference voltage (high) input. ra4/t0cki ra4 t0cki 62323 i/o i ttl st digital i/o. timer0 external clock input. ra5/an4/ss /hlvdin ra5 an4 ss hlvdin 72424 i/o i i i ttl analog ttl analog digital i/o. analog input 4. spi? slave select input. high/low-voltage detect input. ra6 see the osc2/clko/ra6 pin. ra7 see the osc1/clki/ra7 pin. table 1-3: pic18f4585/4680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power
pic18f2585/2680/4585/4680 ds39625b-page 18 preliminary ? 2004 microchip technology inc. portb is a bidirectional i/o port. portb can be software programmed for internal weak pull-ups on all inputs. rb0/int0/flt0/an10 rb0 int0 flt0 an10 33 9 8 i/o i i i ttl st st analog digital i/o. external interrupt 0. enhanced pwm fault input (eccp1 module). analog input 10. rb1/int1/an8 rb1 int1 an8 34 10 9 i/o i i ttl st analog digital i/o. external interrupt 1. analog input 8. rb2/int2/cantx rb2 int2 cantx 35 11 10 i/o i o ttl st ttl digital i/o. external interrupt 2. can bus tx. rb3/canrx rb3 canrx 36 12 11 i/o i ttl ttl digital i/o. can bus rx. rb4/kbi0/an9 rb4 kbi0 an9 37 14 14 i/o i i ttl ttl analog digital i/o. interrupt-on-change pin. analog input 9. rb5/kbi1/pgm rb5 kbi1 pgm 38 15 15 i/o i i/o ttl ttl st digital i/o. interrupt-on-change pin. low-voltage icsp? programming enable pin. rb6/kbi2/pgc rb6 kbi2 pgc 39 16 16 i/o i i/o ttl ttl st digital i/o. interrupt-on-change pin. in-circuit debugger and icsp programming clock pin. rb7/kbi3/pgd rb7 kbi3 pgd 40 17 17 i/o i i/o ttl ttl st digital i/o. interrupt-on-change pin. in-circuit debugger and icsp programming data pin. table 1-3: pic18f4585/4680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power
? 2004 microchip technology inc. preliminary ds39625b-page 19 pic18f2585/2680/4585/4680 portc is a bidirectional i/o port. rc0/t1oso/t13cki rc0 t1oso t13cki 15 34 32 i/o o i st ? st digital i/o. timer1 oscillator output. timer1/timer3 external clock input. rc1/t1osi rc1 t1osi 16 35 35 i/o i st cmos digital i/o. timer1 oscillator input. rc2/ccp1 rc2 ccp1 17 36 36 i/o i/o st st digital i/o. capture1 input/compare1 output/pwm1 output. rc3/sck/scl rc3 sck scl 18 37 37 i/o i/o i/o st st st digital i/o. synchronous serial clock input/output for spi? mode. synchronous serial clock input/output for i 2 c? mode. rc4/sdi/sda rc4 sdi sda 23 42 42 i/o i i/o st st st digital i/o. spi data in. i 2 c data i/o. rc5/sdo rc5 sdo 24 43 43 i/o o st ? digital i/o. spi data out. rc6/tx/ck rc6 tx ck 25 44 44 i/o o i/o st ? st digital i/o. eusart asynchronous transmit. eusart synchronous clock (see related rx/dt). rc7/rx/dt rc7 rx dt 26 1 1 i/o i i/o st st st digital i/o. eusart asynchronous receive. eusart synchronous data (see related tx/ck). table 1-3: pic18f4585/4680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power
pic18f2585/2680/4585/4680 ds39625b-page 20 preliminary ? 2004 microchip technology inc. portd is a bidirectional i/o port or a parallel slave port (psp) for interfacing to a microprocessor port. these pins have ttl input buffers when psp module is enabled. rd0/psp0/c1in+ rd0 psp0 c1in+ 19 38 38 i/o i/o i st ttl analog digital i/o. parallel slave port data. comparator 1 input (+). rd1/psp1/c1in- rd1 psp1 c1in- 20 39 39 i/o i/o i st ttl analog digital i/o. parallel slave port data. comparator 1 input (-) rd2/psp2/c2in+ rd2 psp2 c2in+ 21 40 40 i/o i/o i st ttl analog digital i/o. parallel slave port data. comparator 2 input (+). rd3/psp3/c2in- rd3 psp3 c2in- 22 41 41 i/o i/o i st ttl analog digital i/o. parallel slave port data. comparator 2 input (-). rd4/psp4/eccp1/ p1a rd4 psp4 eccp1 p1a 27 2 2 i/o i/o i/o o st ttl st ttl digital i/o. parallel slave port data. capture2 input/compare2 output/pwm2 output. eccp1 pwm output a. rd5/psp5/p1b rd5 psp5 p1b 28 3 3 i/o i/o o st ttl ttl digital i/o. parallel slave port data. eccp1 pwm output b. rd6/psp6/p1c rd6 psp6 p1c 29 4 4 i/o i/o o st ttl ttl digital i/o. parallel slave port data. eccp1 pwm output c. rd7/psp7/p1d rd7 psp7 p1d 30 5 5 i/o i/o o st ttl ttl digital i/o. parallel slave port data. eccp1 pwm output d. table 1-3: pic18f4585/4680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power
? 2004 microchip technology inc. preliminary ds39625b-page 21 pic18f2585/2680/4585/4680 porte is a bidirectional i/o port. re0/rd /an5 re0 rd an5 82525 i/o i i st ttl analog digital i/o. read control for parallel slave port (see also wr and cs pins). analog input 5. re1/wr /an6/c1out re1 wr an6 c1out 92626 i/o i i o st ttl analog ttl digital i/o. write control for parallel slave port (see cs and rd pins). analog input 6. comparator 1 output. re2/cs /an7/c2out re2 cs an7 c2out 10 27 27 i/o i i o st ttl analog ttl digital i/o. chip select control for parallel slave port (see related rd and wr ). analog input 7. comparator 2 output. re3 ? ? ? ? ? see mclr /v pp /re3 pin. v ss 12, 31 6, 30, 31 6, 29 p ? ground reference for logic and i/o pins. v dd 11, 32 7, 8, 28, 29 7, 28 p ? positive supply for logic and i/o pins. nc ? 13 12, 13, 33, 34 ? ? no connect. table 1-3: pic18f4585/4680 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn tqfp legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power
pic18f2585/2680/4585/4680 ds39625b-page 22 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 23 pic18f2585/2680/4585/4680 2.0 oscillator configurations 2.1 oscillator types pic18f2585/2680/4585/4680 devices can be operated in ten different oscillator modes. the user can program the configuration bits, fosc3:fosc0, in configuration register 1h to select one of these ten modes: 1. lp low-power crystal 2. xt crystal/resonator 3. hs high-speed crystal/resonator 4. hspll high-speed crystal/resonator with pll enabled 5. rc external resistor/capacitor with f osc /4 output on ra6 6. rcio external resistor/capacitor with i/o on ra6 7. intio1 internal oscillator with f osc /4 output on ra6 and i/o on ra7 8. intio2 internal oscillator with i/o on ra6 and ra7 9. ec external clock with f osc /4 output 10. ecio external clock with i/o on ra6 2.2 crystal oscillator/ceramic resonators in xt, lp, hs or hspll oscillator modes, a crystal or ceramic resonator is connected to the osc1 and osc2 pins to establish oscillation. figure 2-1 shows the pin connections. the oscillator design requires the use of a parallel cut crystal. figure 2-1: crystal/ceramic resonator operation (xt, lp, hs or hspll configuration) table 2-1: capacitor selection for ceramic resonators note: use of a series cut crystal may give a frequency out of the crystal manufacturer?s specifications. typical capacitor values used: mode freq osc1 osc2 xt 455 khz 2.0 mhz 4.0 mhz 56 pf 47 pf 33 pf 56 pf 47 pf 33 pf hs 8.0 mhz 16.0 mhz 27 pf 22 pf 27 pf 22 pf capacitor values are for design guidance only. these capacitors were tested with the resonators listed below for basic start-up and operation. these values are not optimized . different capacitor values may be required to produce acceptable oscillator operation. the user should test the performance of the oscillator over the expected v dd and temperature range for the application. see the notes on page 24 for additional information. resonators used: 455 khz 4.0 mhz 2.0 mhz 8.0 mhz 16.0 mhz note: when using resonators with frequencies above 3.5 mhz, the use of hs mode, rather than xt mode, is recommended. hs mode may be used at any v dd for which the controller is rated. if hs is selected, it is possible that the gain of the oscillator will overdrive the resonator. therefore, a series resistor should be placed between the osc2 pin and the resonator. as a good starting point, the recommended value of r s is 330 ? . note 1: see table 2-1 and table 2-2 for initial values of c1 and c2. 2: a series resistor (r s ) may be required for at strip cut crystals. 3: r f varies with the oscillator mode chosen. c1 (1) c2 (1) xtal osc2 osc1 r f (3) sleep to logic pic18fxxxx r s (2) internal
pic18f2585/2680/4585/4680 ds39625b-page 24 preliminary ? 2004 microchip technology inc. table 2-2: capacitor selection for crystal oscillator an external clock source may also be connected to the osc1 pin in the hs mode, as shown in figure 2-2. figure 2-2: external clock input operation (hs oscillator configuration) 2.3 external clock input the ec and ecio oscillator modes require an external clock source to be connected to the osc1 pin. there is no oscillator start-up time required after a power-on reset or after an exit from sleep mode. in the ec oscillator mode, the oscillator frequency divided by 4 is available on the osc2 pin. this signal may be used for test purposes or to synchronize other logic. figure 2-3 shows the pin connections for the ec oscillator mode. figure 2-3: external clock input operation (ec configuration) the ecio oscillator mode functions like the ec mode, except that the osc2 pin becomes an additional general purpose i/o pin. the i/o pin becomes bit 6 of porta (ra6). figure 2-4 shows the pin connections for the ecio oscillator mode. figure 2-4: external clock input operation (ecio configuration) osc type crystal freq typical capacitor values tested: c1 c2 lp 32 khz 33 pf 33 pf 200 khz 15 pf 15 pf xt 1 mhz 33 pf 33 pf 4 mhz 27 pf 27 pf hs 4 mhz 27 pf 27 pf 8 mhz 22 pf 22 pf 20 mhz 15 pf 15 pf capacitor values are for design guidance only. these capacitors were tested with the crystals listed below for basic start-up and operation. these values are not optimized. different capacitor values may be required to produce acceptable oscillator operation. the user should test the performance of the oscillator over the expected v dd and temperature range for the application. see the notes following this table for additional information. crystals used: 32 khz 4 mhz 200 khz 8 mhz 1 mhz 20 mhz note 1: higher capacitance increases the stability of the oscillator but also increases the start-up time. 2: when operating below 3v v dd , or when using certain ceramic resonators at any voltage, it may be necessary to use the hs mode or switch to a crystal oscillator. 3: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. 4: rs may be required to avoid overdriving crystals with low drive level specification. 5: always verify oscillator performance over the v dd and temperature range that is expected for the application. osc1 osc2 open clock from ext. system pic18fxxxx (hs mode) osc1/clki osc2/clko f osc /4 clock from ext. system pic18fxxxx osc1/clki i/o (osc2) ra6 clock from ext. system pic18fxxxx
? 2004 microchip technology inc. preliminary ds39625b-page 25 pic18f2585/2680/4585/4680 2.4 rc oscillator for timing insensitive applications, the ?rc? and ?rcio? device options offer additional cost savings. the actual oscillator frequency is a function of several factors:  supply voltage  values of the external resistor (r ext ) and capacitor (c ext )  operating temperature given the same device, operating voltage and tempera- ture and component values, there will also be unit-to-unit frequency variations. these are due to factors such as:  normal manufacturing variation  difference in lead frame capacitance between package types (especially for low c ext values)  variations within the tolerance of limits of r ext and c ext in the rc oscillator mode, the oscillator frequency divided by 4 is available on the osc2 pin. this signal may be used for test purposes or to synchronize other logic. figure 2-5 shows how the r/c combination is connected. figure 2-5: rc oscillator mode the rcio oscillator mode (figure 2-6) functions like the rc mode, except that the osc2 pin becomes an additional general purpose i/o pin. the i/o pin becomes bit 6 of porta (ra6). figure 2-6: rcio oscillator mode 2.5 pll frequency multiplier a phase locked loop (pll) circuit is provided as an option for users who wish to use a lower frequency oscillator circuit or to clock the device up to its highest rated frequency from a crystal oscillator. this may be useful for customers who are concerned with emi due to high-frequency crystals or users who require higher clock speeds from an internal oscillator. 2.5.1 hspll oscillator mode the hspll mode makes use of the hs mode oscillator for frequencies up to 10 mhz. a pll then multiplies the oscillator output frequency by 4 to produce an internal clock frequency up to 40 mhz. the pll is only available to the crystal oscillator when the fosc3:fosc0 configuration bits are programmed for hspll mode (= 0110 ). figure 2-7: pll block diagram (hs mode) 2.5.2 pll and intosc the pll is also available to the internal oscillator block in selected oscillator modes. in this configuration, the pll is enabled in software and generates a clock output of up to 32 mhz. the operation of intosc with the pll is described in section 2.6.4 ?pll in intosc modes? . osc2/clko c ext r ext pic18fxxxx osc1 f osc /4 internal clock v dd v ss recommended values: 3 k ? r ext 100 k ? c ext > 20 pf c ext r ext pic18fxxxx osc1 internal clock v dd v ss recommended values: 3 k ? r ext 100 k ? c ext > 20 pf i/o (osc2) ra6 mux vco loop filter crystal osc osc2 osc1 pll enable f in f out sysclk phase comparator hs osc enable 4 (from configuration register 1h) hs mode
pic18f2585/2680/4585/4680 ds39625b-page 26 preliminary ? 2004 microchip technology inc. 2.6 internal oscillator block the pic18f2585/2680/4585/4680 devices include an internal oscillator block which generates two different clock signals; either can be used as the microcontroller?s clock source. this may eliminate the need for external oscillator circuits on the osc1 and/or osc2 pins. the main output (intosc) is an 8 mhz clock source, which can be used to directly drive the device clock. it also drives a postscaler, which can provide a range of clock frequencies from 31 khz to 4 mhz. the intosc output is enabled when a clock frequency from 125 khz to 8 mhz is selected. the other clock source is the internal rc oscillator (intrc), which provides a nominal 31 khz output. intrc is enabled if it is selected as the device clock source; it is also enabled automatically when any of the following are enabled:  power-up timer  fail-safe clock monitor  watchdog timer  two-speed start-up these features are discussed in greater detail in section 24.0 ?special features of the cpu? . the clock source frequency (intosc direct, intrc direct or intosc postscaler) is selected by configuring the ircf bits of the osccon register (register 2-2). 2.6.1 intio modes using the internal oscillator as the clock source eliminates the need for up to two external oscillator pins, which can then be used for digital i/o. two distinct configurations are available:  in intio1 mode, the osc2 pin outputs f osc /4, while osc1 functions as ra7 for digital input and output.  in intio2 mode, osc1 functions as ra7 and osc2 functions as ra6, both for digital input and output. 2.6.2 intosc output frequency the internal oscillator block is calibrated at the factory to produce an intosc output frequency of 8.0 mhz. the intrc oscillator operates independently of the intosc source. any changes in intosc across voltage and temperature are not necessarily reflected by changes in intrc and vice versa. 2.6.3 osctune register the internal oscillator?s output has been calibrated at the factory but can be adjusted in the user?s applica- tion. this is done by writing to the osctune register (register 2-1). the tuning sensitivity is constant throughout the tuning range. when the osctune register is modified, the intosc and intrc frequencies will begin shifting to the new frequency. the intrc clock will reach the new frequency within 8 clock cycles (approximately 8*32 s = 256 s). the intosc clock will stabilize within 1 ms. code execution continues during this shift. there is no indication that the shift has occurred. the osctune register also implements the intsrc and pllen bits, which control certain features of the internal oscillator block. the intsrc bit allows users to select which internal oscillator provides the clock source when the 31 khz frequency option is selected. this is covered in greater detail in section 2.7.1 ?oscillator control register? . the pllen bit controls the operation of the frequency multiplier, pll, in internal oscillator modes. 2.6.4 pll in intosc modes the 4x frequency multiplier can be used with the inter- nal oscillator block to produce faster device clock speeds than are normally possible with an internal oscillator. when enabled, the pll produces a clock speed of up to 32 mhz. unlike hspll mode, the pll is controlled through soft- ware. the control bit, pllen (osctune<6>), is used to enable or disable its operation. the pll is available when the device is configured to use the internal oscillator block as its primary clock source (fosc3:fosc0 = 1001 or 1000 ). additionally, the pll will only function when the selected output fre- quency is either 4 mhz or 8 mhz (osccon<6:4> = 111 or 110 ). if both of these conditions are not met, the pll is disabled. the pllen control bit is only functional in those internal oscillator modes where the pll is available. in all other modes, it is forced to ? 0 ? and is effectively unavailable. 2.6.5 intosc frequency drift the factory calibrates the internal oscillator block output (intosc) for 8 mhz. however, this frequency may drift as v dd or temperature changes, which can affect the controller operation in a variety of ways. it is possible to adjust the intosc frequency by modifying the value in the osctune register. this has no effect on the intrc clock source frequency. tuning the intosc source requires knowing when to make the adjustment, in which direction it should be made and in some cases, how large a change is needed. three compensation techniques are discussed in section 2.6.5.1 ?compensating with the eusart? , section 2.6.5.2 ?compensating with the timers? and section 2.6.5.3 ?compensating with the ccp1 module in capture mode? , but other techniques may be used.
? 2004 microchip technology inc. preliminary ds39625b-page 27 pic18f2585/2680/4585/4680 register 2-1: osctune: oscillator tuning register 2.6.5.1 compensating with the eusart an adjustment may be required when the eusart begins to generate framing errors or receives data with errors while in asynchronous mode. framing errors indicate that the device clock frequency is too high. to adjust for this, decrement the value in osctune to reduce the clock frequency. on the other hand, errors in data may suggest that the clock speed is too low. to compensate, increment osctune to increase the clock frequency. 2.6.5.2 compensating with the timers this technique compares device clock speed to some reference clock. two timers may be used; one timer is clocked by the peripheral clock, while the other is clocked by a fixed reference source, such as the timer1 oscillator. both timers are cleared, but the timer clocked by the reference generates interrupts. when an interrupt occurs, the internally clocked timer is read and both timers are cleared. if the internally clocked timer value is greater than expected, then the internal oscillator block is running too fast. to adjust for this, decrement the osctune register. 2.6.5.3 compensating with the ccp1 module in capture mode the ccp1 module can use free running timer1 (or timer3), clocked by the internal oscillator block and an external event with a known period (i.e., ac power frequency). the time of the first event is captured in the ccprxh:ccprxl registers and is recorded for use later. when the second event causes a capture, the time of the first event is subtracted from the time of the second event. since the period of the external event is known, the time difference between events can be calculated. if the measured time is much greater than the calculated time, the internal oscillator block is running too fast. to compensate, decrement the osctune register. if the measured time is much less than the calculated time, the internal oscillator block is running too slow. to compensate, increment the osctune register. r/w-0 r/w-0 (1) u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 intsrc pllen (1) ? tun4 tun3 tun2 tun1 tun0 bit 7 bit 0 bit 7 intsrc: internal oscillator low-frequency source select bit 1 = 31.25 khz device clock derived from 8 mhz intosc source (divide-by-256 enabled) 0 = 31 khz device clock derived directly from intrc internal oscillator bit 6 pllen: frequency multiplier pll for intosc enable bit (1) 1 = pll enabled for intosc (4 mhz and 8 mhz only) 0 = pll disabled note 1: available only in certain oscillator configurations; otherwise, this bit is unavailable and reads as ? 0 ?. see text for details. bit 5 unimplemented: read as ? 0 ? bit 4-0 tun4:tun0: frequency tuning bits 01111 = maximum frequency     00001 00000 = center frequency. oscillator module is running at the calibrated frequency. 11111     10000 = minimum frequency legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 28 preliminary ? 2004 microchip technology inc. 2.7 clock sources and oscillator switching like previous pic18 devices, the pic2585/2680/ 4585/4680 family includes a feature that allows the device clock source to be switched from the main oscillator to an alternate low-frequency clock source. pic18f2585/2680/4585/4680 devices offer two alter- nate clock sources. when an alternate clock source is enabled, the various power managed operating modes are available. essentially, there are three clock sources for these devices:  primary oscillators  secondary oscillators  internal oscillator block the primary oscillators include the external crystal and resonator modes, the external rc modes, the external clock modes and the internal oscillator block. the particular mode is defined by the fosc3:fosc0 configuration bits. the details of these modes are covered earlier in this chapter. the secondary oscillators are those external sources not connected to the osc1 or osc2 pins. these sources may continue to operate even after the controller is placed in a power managed mode. pic18f2585/2680/4585/4680 devices offer the timer1 oscillator as a secondary oscillator. this oscillator, in all power managed modes, is often the time base for functions such as a real-time clock. most often, a 32.768 khz watch crystal is connected between the rc0/t1oso/t13cki and rc1/t1osi pins. like the lp mode oscillator circuit, loading capacitors are also connected from each pin to ground. the timer1 oscillator is discussed in greater detail in section 12.3 ?timer1 oscillator? . in addition to being a primary clock source, the internal oscillator block is available as a power managed mode clock source. the intrc source is also used as the clock source for several special features, such as the wdt and fail-safe clock monitor. the clock sources for the pic18f2585/2680/4585/4680 devices are shown in figure 2-8. see section 24.0 ?special features of the cpu? for configuration register details. figure 2-8: pic18f2585/2680/4585/4680 clock diagram pic18fx585/x680 4 x pll fosc3:fosc0 secondary oscillator t1oscen enable oscillator t1oso t1osi clock source option for other modules osc1 osc2 sleep primary oscillator hspll, intosc/pll lp, xt, hs, rc, ec t1osc cpu peripherals idlen postscaler mux mux 8 mhz 4 mhz 2 mhz 1 mhz 500 khz 125 khz 250 khz osccon<6:4> 111 110 101 100 011 010 001 000 31 khz intrc source internal oscillator block wdt, pwrt, fscm 8 mhz internal oscillator (intosc) osccon<6:4> clock control osccon<1:0> source 8 mhz 31 khz (intrc) osctune<6> 0 1 osctune<7> and two-speed startup
? 2004 microchip technology inc. preliminary ds39625b-page 29 pic18f2585/2680/4585/4680 2.7.1 oscillator control register the osccon register (register 2-2) controls several aspects of the device clock?s operation, both in full power operation and in power managed modes. the system clock select bits, scs1:scs0, select the clock source. the available clock sources are the primary clock (defined by the fosc3:fosc0 configu- ration bits), the secondary clock (timer1 oscillator) and the internal oscillator block. the clock source changes immediately after one or more of the bits is written to, following a brief clock transition interval. the scs bits are cleared on all forms of reset. the internal oscillator frequency select bits, ircf2:ircf0, select the frequency output of the internal oscillator block to drive the device clock. the choices are the intrc source, the intosc source (8 mhz) or one of the frequencies derived from the intosc postscaler (31 khz to 4 mhz). if the internal oscillator block is supplying the device clock, changing the states of these bits will have an immediate change on the internal oscillator?s output. on device resets, the default output frequency of the internal oscillator block is set at 1 mhz. when an output frequency of 31 khz is selected (ircf2:ircf0 = 000 ), users may choose which internal oscillator acts as the source. this is done with the intsrc bit in the osctune register (osctune<7>). setting this bit selects intosc as a 31.25 khz clock source by enabling the divide-by-256 output of the intosc postscaler. clearing intsrc selects intrc (nominally 31 khz) as the clock source. this option allows users to select the tunable and more precise intosc as a clock source, while maintaining power savings with a very low clock speed. regardless of the setting of intsrc, intrc always remains the clock source for features such as the watchdog timer and the fail-safe clock monitor. the osts, iofs and t1run bits indicate which clock source is currently providing the device clock. the osts bit indicates that the oscillator start-up timer has timed out and the primary clock is providing the device clock in primary clock modes. the iofs bit indicates when the internal oscillator block has stabilized and is providing the device clock in rc clock modes. the t1run bit (t1con<6>) indicates when the timer1 oscillator is providing the device clock in secondary clock modes. in power managed modes, only one of these three bits will be set at any time. if none of these bits are set, the intrc is providing the clock or the internal oscillator block has just started and is not yet stable. the idlen bit determines if the device goes into sleep mode or one of the idle modes when the sleep instruction is executed. the use of the flag and control bits in the osccon register is discussed in more detail in section 3.0 ?power managed modes? . 2.7.2 oscillator transitions pic18f2585/2680/4585/4680 devices contain circuitry to prevent clock ?glitches? when switching between clock sources. a short pause in the device clock occurs during the clock switch. the length of this pause is the sum of two cycles of the old clock source and three to four cycles of the new clock source. this formula assumes that the new clock source is stable. clock transitions are discussed in greater detail in section 3.1.2 ?entering power managed modes? . note 1: the timer1 oscillator must be enabled to select the secondary clock source. the timer1 oscillator is enabled by setting the t1oscen bit in the timer1 control regis- ter (t1con<3>). if the timer1 oscillator is not enabled, then any attempt to select a secondary clock source when executing a sleep instruction will be ignored. 2: it is recommended that the timer1 oscillator be operating and stable before executing the sleep instruction, or a very long delay may occur while the timer1 oscillator starts.
pic18f2585/2680/4585/4680 ds39625b-page 30 preliminary ? 2004 microchip technology inc. register 2-2: osccon: oscillator co ntrol register r/w-0 r/w-1 r/w-0 r/w-0 r (1) r-0 r/w-0 r/w-0 idlen ircf2 ircf1 ircf0 osts iofs scs1 scs0 bit 7 bit 0 bit 7 idlen: idle enable bit 1 = device enters idle mode on sleep instruction 0 = device enters sleep mode on sleep instruction bit 6-4 ircf2:ircf0: internal oscillator frequency select bits 111 = 8 mhz (intosc drives clock directly) 110 = 4 mhz 101 = 2 mhz 100 = 1 mhz (3) 011 = 500 khz 010 = 250 khz 001 = 125 khz 000 = 31 khz (from either intosc/256 or intrc directly) (2) bit 3 osts: oscillator start-up time-out status bit (1) 1 = oscillator start-up time-out timer has expired; primary oscillator is running 0 = oscillator start-up time-out timer is running; primary oscillator is not ready bit 2 iofs: intosc frequency stable bit 1 = intosc frequency is stable and the frequency is provided by one of the rc modes 0 = intosc frequency is not stable bit 1-0 scs1:scs0: system clock select bits 1x = internal oscillator block 01 = timer1 oscillator 00 = primary oscillator note 1: depends on state of the ieso configuration bit. 2: source selected by the intsrc bit (osctune<7>), see text. 3: default output frequency of intosc on reset. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 31 pic18f2585/2680/4585/4680 2.8 effects of power managed modes on the various clock sources when pri_idle mode is selected, the designated primary oscillator continues to run without interruption. for all other power managed modes, the oscillator using the osc1 pin is disabled. the osc1 pin (and osc2 pin, if used by the oscillator) will stop oscillating. in secondary clock modes (sec_run and sec_idle), the timer1 oscillator is operating and providing the device clock. the timer1 oscillator may also run in all power managed modes if required to clock timer1 or timer3. in internal oscillator modes (rc_run and rc_idle), the internal oscillator block provides the device clock source. the 31 khz intrc output can be used directly to provide the clock and may be enabled to support various special features, regardless of the power managed mode (see section 24.2 ?watchdog timer (wdt)? , section 24.3 ?two-speed start-up? and section 24.4 ?fail-safe clock monitor? for more information on wdt, two-speed start-up and fail-safe clock monitor). the intosc output at 8 mhz may be used directly to clock the device or may be divided down by the postscaler. the intosc output is disabled if the clock is provided directly from the intrc output. if the sleep mode is selected, all clock sources are stopped. since all the transistor switching currents have been stopped, sleep mode achieves the lowest current consumption of the device (only leakage currents). enabling any on-chip feature that will operate during sleep will increase the current consumed during sleep. the intrc is required to support wdt operation. the timer1 oscillator may be operating to support a real-time clock. other features may be operating that do not require a device clock source (i.e., ssp slave, psp, intn pins and others). peripherals that may add significant current consumption are listed in section 27.2 ?dc characteristics: power down and supply current?. 2.9 power-up delays power-up delays are controlled by two timers, so that no external reset circuitry is required for most applica- tions. the delays ensure that the device is kept in reset until the device power supply is stable under nor- mal circumstances and the primary clock is operating and stable. for additional information on power-up delays, see section 4.5 ?device reset timers? . the first timer is the power-up timer (pwrt), which provides a fixed delay on power-up (parameter 33, table 27-10). it is enabled by clearing (= 0 ) the pwrten configuration bit. the second timer is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable (lp, xt and hs modes). the ost does this by counting 1024 oscillator cycles before allowing the oscillator to clock the device. when the hspll oscillator mode is selected, the device is kept in reset for an additional 2 ms, following the hs mode ost delay, so the pll can lock to the incoming clock frequency. there is a delay of interval t csd (parameter 38, table 27-10), following por, while the controller becomes ready to execute instructions. this delay runs concurrently with any other delays. this may be the only delay that occurs when any of the ec, rc or intio modes are used as the primary clock source. table 2-3: osc1 and osc2 pin states in sleep mode osc mode osc1 pin osc2 pin rc, intio1 floating, external resistor should pull high at logic low (clock/4 output) rcio, intio2 floating, external resistor should pull high configured as porta, bit 6 ecio floating, pulled by external clock configured as porta, bit 6 ec floating, pulled by external clock at logic low (clock/4 output) lp, xt and hs feedback inverter disabled at quiescent voltage level feedback inverter disabled at quiescent voltage level note: see table 4-2 in section 4.0 ?reset? for time-outs due to sleep and mclr reset.
pic18f2585/2680/4585/4680 ds39625b-page 32 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 33 pic18f2585/2680/4585/4680 3.0 power managed modes pic18f2585/2680/4585/4680 devices offer a total of seven operating modes for more efficient power management. these modes provide a variety of options for selective power conservation in applications where resources may be limited (i.e., battery-powered devices). there are three categories of power managed modes:  run modes  idle modes  sleep mode these categories define which portions of the device are clocked and sometimes, what speed. the run and idle modes may use any of the three available clock sources (primary, secondary or internal oscillator block); the sleep mode does not use a clock source. the power managed modes include several power saving features offered on previous picmicro ? devices. one is the clock switching feature, offered in other pic18 devices, allowing the controller to use the timer1 oscillator in place of the primary oscillator. also included is the sleep mode, offered by all picmicro devices, where all device clocks are stopped. 3.1 selecting power managed modes selecting a power managed mode requires two decisions: if the cpu is to be clocked or not and the selection of a clock source. the idlen bit (osccon<7>) controls cpu clocking, while the scs1:scs0 bits (osccon<1:0>) select the clock source. the individual modes, bit settings, clock sources and affected modules are summarized in table 3-1. 3.1.1 clock sources the scs1:scs0 bits allow the selection of one of three clock sources for power managed modes. they are:  the primary clock, as defined by the fosc3:fosc0 configuration bits  the secondary clock (the timer1 oscillator)  the internal oscillator block (for rc modes) 3.1.2 entering power managed modes switching from one power managed mode to another begins by loading the osccon register. the scs1:scs0 bits select the clock source and determine which run or idle mode is to be used. changing these bits causes an immediate switch to the new clock source, assuming that it is running. the switch may also be subject to clock transition delays. these are discussed in section 3.1.3 ?clock transitions and status indicators? and subsequent sections. entry to the power managed idle or sleep modes is triggered by the execution of a sleep instruction. the actual mode that results depends on the status of the idlen bit. depending on the current mode and the mode being switched to, a change to a power managed mode does not always require setting all of these bits. many transitions may be done by changing the oscillator select bits, or changing the idlen bit, prior to issuing a sleep instruction. if the idlen bit is already configured correctly, it may only be necessary to perform a sleep instruction to switch to the desired mode. table 3-1: power managed modes mode osccon bits module clocking available clock and oscillator source idlen<7> (1) scs1:scs0<1:0> cpu peripherals sleep 0 n/a off off none ? all clocks are disabled pri_run n/a 00 clocked clocked primary ? lp, xt, hs, hspll, rc, ec, intrc (2) : this is the normal full power execution mode. sec_run n/a 01 clocked clocked secondary ? timer1 oscillator rc_run n/a 1x clocked clocked internal oscillator block (2) pri_idle 100 off clocked primary ? lp, xt, hs, hspll, rc, ec sec_idle 101 off clocked secondary ? timer1 oscillator rc_idle 11x off clocked internal oscillator block (2) note 1: idlen reflects its value when the sleep instruction is executed. 2: includes intosc and intosc postsc aler, as well as the intrc source.
pic18f2585/2680/4585/4680 ds39625b-page 34 preliminary ? 2004 microchip technology inc. 3.1.3 clock transitions and status indicators the length of the transition between clock sources is the sum of two cycles of the old clock source and three to four cycles of the new clock source. this formula assumes that the new clock source is stable. three bits indicate the current clock source and its status. they are:  osts (osccon<3>)  iofs (osccon<2>)  t1run (t1con<6>) in general, only one of these bits will be set while in a given power managed mode. when the osts bit is set, the primary clock is providing the device clock. when the iofs bit is set, the intosc output is provid- ing a stable 8 mhz clock source to a divider that actually drives the device clock. when the t1run bit is set, the timer1 oscillator is providing the clock. if none of these bits are set, then either the intrc clock source is clocking the device, or the intosc source is not yet stable. if the internal oscillator block is configured as the primary clock source by the fosc3:fosc0 configura- tion bits, then both the osts and iofs bits may be set when in pri_run or pri_idle modes. this indicates that the primary clock (intosc output) is generating a stable 8 mhz output. entering another rc power managed mode at the same frequency would clear the osts bit. 3.1.4 multiple sleep commands the power managed mode that is invoked with the sleep instruction is determined by the setting of the idlen bit at the time the instruction is executed. if another sleep instruction is executed, the device will enter the power managed mode specified by idlen at that time. if idlen has changed, the device will enter the new power managed mode specified by the new setting. 3.2 run modes in the run modes, clocks to both the core and peripherals are active. the difference between these modes is the clock source. 3.2.1 pri_run mode the pri_run mode is the normal, full power execution mode of the microcontroller. this is also the default mode upon a device reset, unless two-speed start-up is enabled (see section 24.3 ?two-speed start-up? for details). in this mode, the osts bit is set. the iofs bit may be set if the internal oscillator block is the primary clock source (see section 2.7.1 ?oscillator control register? ). 3.2.2 sec_run mode the sec_run mode is the compatible mode to the ?clock switching? feature offered in other pic18 devices. in this mode, the cpu and peripherals are clocked from the timer1 oscillator. this gives users the option of lower power consumption while still using a high accuracy clock source. sec_run mode is entered by setting the scs1:scs0 bits to ? 01 ?. the device clock source is switched to the timer1 oscillator (see figure 3-1), the primary oscilla- tor is shut down, the t1run bit (t1con<6>) is set and the osts bit is cleared. on transitions from sec_run mode to pri_run, the peripherals and cpu continue to be clocked from the timer1 oscillator while the primary clock is started. when the primary clock becomes ready, a clock switch back to the primary clock occurs (see figure 3-2). when the clock switch is complete, the t1run bit is cleared, the osts bit is set and the primary clock is providing the clock. the idlen and scs bits are not affected by the wake-up; the timer1 oscillator continues to run. note 1: caution should be used when modifying a single ircf bit. if v dd is less than 3v, it is possible to select a higher clock speed than is supported by the low v dd . improper device operation may result if the v dd /f osc specifications are violated. 2: executing a sleep instruction does not necessarily place the device into sleep mode. it acts as the trigger to place the controller into either the sleep mode or one of the idle modes, depending on the setting of the idlen bit. note: the timer1 oscillator should already be running prior to entering sec_run mode. if the t1oscen bit is not set when the scs1:scs0 bits are set to ? 01 ?, entry to sec_run mode will not occur. if the timer1 oscillator is enabled but not yet running, device clocks will be delayed until the oscillator has started. in such situa- tions, initial oscillator operation is far from stable and unpredictable operation may result.
? 2004 microchip technology inc. preliminary ds39625b-page 35 pic18f2585/2680/4585/4680 figure 3-1: transition timing for entry to sec_run mode figure 3-2: transition timing from sec_run mode to pri_run mode (hspll) 3.2.3 rc_run mode in rc_run mode, the cpu and peripherals are clocked from the internal oscillator block using the intosc multiplexer; the primary clock is shut down. when using the intrc source, this mode provides the best power conservation of all the run modes, while still executing code. it works well for user applications which are not highly timing sensitive or do not require high-speed clocks at all times. if the primary clock source is the internal oscillator block (either intrc or intosc), there are no distin- guishable differences between pri_run and rc_run modes during execution. however, a clock switch delay will occur during entry to and exit from rc_run mode. therefore, if the primary clock source is the internal oscillator block, the use of rc_run mode is not recommended. this mode is entered by setting scs1 to ? 1 ?. although it is ignored, it is recommended that scs0 also be cleared; this is to maintain software compatibility with future devices. when the clock source is switched to the intosc multiplexer (see figure 3-3), the primary oscillator is shut down and the osts bit is cleared. the ircf bits may be modified at any time to immediately change the clock speed. q4 q3 q2 osc1 peripheral program q1 t1osi q1 counter clock cpu clock pc + 2 pc 123 n-1 n clock transition q4 q3 q2 q1 q3 q2 pc + 4 q1 q3 q4 osc1 peripheral program pc t1osi pll clock q1 pc + 4 q2 output q3 q4 q1 cpu clock pc + 2 clock counter q2 q2 q3 note 1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. scs1:scs0 bits changed t ost (1) t pll (1) 12 n-1n clock osts bit set transition note: caution should be used when modifying a single ircf bit. if v dd is less than 3v, it is possible to select a higher clock speed than is supported by the low v dd . improper device operation may result if the v dd /f osc specifications are violated.
pic18f2585/2680/4585/4680 ds39625b-page 36 preliminary ? 2004 microchip technology inc. if the ircf bits and the intsrc bit are all clear, the intosc output is not enabled and the iofs bit will remain clear; there will be no indication of the current clock source. the intrc source is providing the device clocks. if the ircf bits are changed from all clear (thus, enabling the intosc output) or if intsrc is set, the iofs bit becomes set after the intosc output becomes stable. clocks to the device continue while the intosc source stabilizes after an interval of t iobst . if the ircf bits were previously at a non-zero value or if intsrc was set before setting scs1 and the intosc source was already stable, the iofs bit will remain set. on transitions from rc_run mode to pri_run mode, the device continues to be clocked from the intosc multiplexer while the primary clock is started. when the primary clock becomes ready, a clock switch to the primary clock occurs (see figure 3-4). when the clock switch is complete, the iofs bit is cleared, the osts bit is set and the primary clock is providing the device clock. the idlen and scs bits are not affected by the switch. the intrc source will continue to run if either the wdt or the fail-safe clock monitor is enabled. figure 3-3: transition timing to rc_run mode figure 3-4: transition timing fr om rc_run mode to pri_run mode q4 q3 q2 osc1 peripheral program q1 intrc q1 counter clock cpu clock pc + 2 pc 123 n-1n clock transition q4 q3 q2 q1 q3 q2 pc + 4 q1 q3 q4 osc1 peripheral program pc intosc pll clock q1 pc + 4 q2 output q3 q4 q1 cpu clock pc + 2 clock counter q2 q2 q3 note 1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. scs1:scs0 bits changed t pll (1) 12 n-1n clock osts bit set transition multiplexer t ost (1)
? 2004 microchip technology inc. preliminary ds39625b-page 37 pic18f2585/2680/4585/4680 3.3 sleep mode the power managed sleep mode in the pic18f2585/2680/4585/4680 devices is identical to the legacy sleep mode offered in all other picmicro devices. it is entered by clearing the idlen bit (the default state on device reset) and executing the sleep instruction. this shuts down the selected oscillator (figure 3-5). all clock source status bits are cleared. entering the sleep mode from any other mode does not require a clock switch. this is because no clocks are needed once the controller has entered sleep. if the wdt is selected, the intrc source will continue to operate. if the timer1 oscillator is enabled, it will also continue to run. when a wake event occurs in sleep mode (by interrupt, reset or wdt time-out), the device will not be clocked until the clock source selected by the scs1:scs0 bits becomes ready (see figure 3-6), or it will be clocked from the internal oscillator block if either the two-speed start-up or the fail-safe clock monitor are enabled (see section 24.0 ?special features of the cpu? ). in either case, the osts bit is set when the primary clock is providing the device clocks. the idlen and scs bits are not affected by the wake-up. 3.4 idle modes the idle modes allow the controller?s cpu to be selectively shut down while the peripherals continue to operate. selecting a particular idle mode allows users to further manage power consumption. if the idlen bit is set to a ? 1 ? when a sleep instruction is executed, the peripherals will be clocked from the clock source selected using the scs1:scs0 bits; however, the cpu will not be clocked. the clock source status bits are not affected. setting idlen and executing a sleep instruction provides a quick method of switching from a given run mode to its corresponding idle mode. if the wdt is selected, the intrc source will continue to operate. if the timer1 oscillator is enabled, it will also continue to run. since the cpu is not executing instructions, the only exits from any of the idle modes are by interrupt, wdt time-out or a reset. when a wake event occurs, cpu execution is delayed by an interval of t csd (parameter 38, table 27-10) while it becomes ready to execute code. when the cpu begins executing code, it resumes with the same clock source for the current idle mode. for example, when waking from rc_idle mode, the internal oscillator block will clock the cpu and peripherals (in other words, rc_run mode). the idlen and scs bits are not affected by the wake-up. while in any idle mode or the sleep mode, a wdt time-out will result in a wdt wake-up to the run mode currently specified by the scs1:scs0 bits. figure 3-5: transition timing for entry to sleep mode figure 3-6: transition timing for wake from sleep (hspll) q4 q3 q2 osc1 peripheral sleep program q1 q1 counter clock cpu clock pc + 2 pc q3 q4 q1 q2 osc1 peripheral program pc pll clock q3 q4 output cpu clock q1 q2 q3 q4 q1 q2 clock counter pc + 6 pc + 4 q1 q2 q3 q4 wake event note1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. t ost (1) t pll (1) osts bit set pc + 2
pic18f2585/2680/4585/4680 ds39625b-page 38 preliminary ? 2004 microchip technology inc. 3.4.1 pri_idle mode this mode is unique among the three low-power idle modes, in that it does not disable the primary device clock. for timing sensitive applications, this allows for the fastest resumption of device operation with its more accurate primary clock source, since the clock source does not have to ?warm up? or transition from another oscillator. pri_idle mode is entered from pri_run mode by setting the idlen bit and executing a sleep instruc- tion. if the device is in another run mode, set idlen first, then clear the scs bits and execute sleep . although the cpu is disabled, the peripherals continue to be clocked from the primary clock source specified by the fosc3:fosc0 configuration bits. the osts bit remains set (see figure 3-7). when a wake event occurs, the cpu is clocked from the primary clock source. a delay of interval t csd is required between the wake event and when code execution starts. this is required to allow the cpu to become ready to execute instructions. after the wake-up, the osts bit remains set. the idlen and scs bits are not affected by the wake-up (see figure 3-8). 3.4.2 sec_idle mode in sec_idle mode, the cpu is disabled but the peripherals continue to be clocked from the timer1 oscillator. this mode is entered from sec_run by set- ting the idlen bit and executing a sleep instruction. if the device is in another run mode, set the idlen bit first, then set the scs1:scs0 bits to ? 01 ? and execute sleep . when the clock source is switched to the timer1 oscillator, the primary oscillator is shut down, the osts bit is cleared and the t1run bit is set. when a wake event occurs, the peripherals continue to be clocked from the timer1 oscillator. after an interval of t csd following the wake event, the cpu begins executing code being clocked by the timer1 oscillator. the idlen and scs bits are not affected by the wake-up; the timer1 oscillator continues to run (see figure 3-8). figure 3-7: transition timing for entry to idle mode figure 3-8: transition timing for wake from idle to run mode note: the timer1 oscillator should already be running prior to entering sec_idle mode. if the t1oscen bit is not set when the sleep instruction is executed, the sleep instruction will be ignored and entry to sec_idle mode will not occur. if the timer1 oscillator is enabled but not yet run- ning, peripheral clocks will be delayed until the oscillator has started. in such situations, initial oscillator operation is far from stable and unpredictable operation may result. q1 peripheral program pc pc + 2 osc1 q3 q4 q1 cpu clock clock counter q2 osc1 peripheral program pc cpu clock q1 q3 q4 clock counter q2 wake event t csd
? 2004 microchip technology inc. preliminary ds39625b-page 39 pic18f2585/2680/4585/4680 3.4.3 rc_idle mode in rc_idle mode, the cpu is disabled but the periph- erals continue to be clocked from the internal oscillator block using the intosc multiplexer. this mode allows for controllable power conservation during idle periods. from rc_run, this mode is entered by setting the idlen bit and executing a sleep instruction. if the device is in another run mode, first set idlen, then set the scs1 bit and execute sleep . although its value is ignored, it is recommended that scs0 also be cleared; this is to maintain software compatibility with future devices. the intosc multiplexer may be used to select a higher clock frequency, by modifying the ircf bits, before executing the sleep instruction. when the clock source is switched to the intosc multiplexer, the primary oscillator is shut down and the osts bit is cleared. if the ircf bits are set to any non-zero value or the intsrc bit is set, the intosc output is enabled. the iofs bit becomes set, after the intosc output becomes stable, after an interval of t iobst (parameter 39, table 27-10). clocks to the peripherals continue while the intosc source stabilizes. if the ircf bits were previously at a non-zero value, or intsrc was set before the sleep instruction was executed and the intosc source was already stable, the iofs bit will remain set. if the ircf bits and intsrc are all clear, the intosc output will not be enabled, the iofs bit will remain clear and there will be no indication of the current clock source. when a wake event occurs, the peripherals continue to be clocked from the intosc multiplexer. after a delay of t csd following the wake event, the cpu begins executing code being clocked by the intosc multi- plexer. the idlen and scs bits are not affected by the wake-up. the intrc source will continue to run if either the wdt or the fail-safe clock monitor is enabled. 3.5 exiting idle and sleep modes an exit from sleep mode or any of the idle modes is triggered by an interrupt, a reset or a wdt time-out. this section discusses the triggers that cause exits from power managed modes. the clocking subsystem actions are discussed in each of the power managed modes (see section 3.2 ?run modes?, section 3.3 ?sleep mode? and section 3.4 ?idle modes? ). 3.5.1 exit by interrupt any of the available interrupt sources can cause the device to exit from an idle mode or the sleep mode to a run mode. to enable this functionality, an interrupt source must be enabled by setting its enable bit in one of the intcon or pie registers. the exit sequence is initiated when the corresponding interrupt flag bit is set. on all exits from idle or sleep modes by interrupt, code execution branches to the interrupt vector if the gie/gieh bit (intcon<7>) is set. otherwise, code execution continues or resumes without branching (see section 9.0 ?interrupts? ). a fixed delay of interval t csd following the wake event is required when leaving sleep and idle modes. this delay is required for the cpu to prepare for execution. instruction execution resumes on the first clock cycle following this delay. 3.5.2 exit by wdt time-out a wdt time-out will cause different actions depending on which power managed mode the device is in when the time-out occurs. if the device is not executing code (all idle modes and sleep mode), the time-out will result in an exit from the power managed mode (see section 3.2 ?run modes? and section 3.3 ?sleep mode? ). if the device is executing code (all run modes), the time-out will result in a wdt reset (see section 24.2 ?watchdog timer (wdt)? ). the wdt timer and postscaler are cleared by execut- ing a sleep or clrwdt instruction, the loss of a currently selected clock source (if the fail-safe clock monitor is enabled) and modifying the ircf bits in the osccon register if the internal oscillator block is the device clock source. 3.5.3 exit by reset normally, the device is held in reset by the oscillator start-up timer (ost) until the primary clock becomes ready. at that time, the osts bit is set and the device begins executing code. if the internal oscillator block is the new clock source, the iofs bit is set instead. the exit delay time from reset to the start of code execution depends on both the clock sources before and after the wake-up and the type of oscillator if the new clock source is the primary clock. exit delays are summarized in table 3-2. code execution can begin before the primary clock becomes ready. if either the two-speed start-up (see section 24.3 ?two-speed start-up? ) or fail-safe clock monitor (see section 24.4 ?fail-safe clock monitor? ) is enabled, the device may begin execution as soon as the reset source has cleared. execution is clocked by the intosc multiplexer driven by the internal oscillator block. execution is clocked by the internal oscillator block until either the primary clock becomes ready or a power managed mode is entered before the primary clock becomes ready; the primary clock is then shut down.
pic18f2585/2680/4585/4680 ds39625b-page 40 preliminary ? 2004 microchip technology inc. 3.5.4 exit without an oscillator start-up delay certain exits from power managed modes do not invoke the ost at all. there are two cases:  pri_idle mode where the primary clock source is not stopped; and  the primary clock source is not any of the lp, xt, hs or hspll modes. in these instances, the primary clock source either does not require an oscillator start-up delay, since it is already running (pri_idle), or normally does not require an oscillator start-up delay (rc, ec and intio oscillator modes). however, a fixed delay of interval t csd following the wake event is still required when leaving sleep and idle modes to allow the cpu to pre- pare for execution. instruction execution resumes on the first clock cycle following this delay. table 3-2: exit delay on wake-up by reset from sleep mode or any idle mode (by clock sources) clock source before wake-up clock source after wake-up exit delay clock ready status bit (osccon) primary device clock (pri_idle mode) lp, xt, hs t csd (2) osts hspll ec, rc intrc (1) ? intosc (3) iofs t1osc or intrc (1) lp, xt, hs t ost (4) osts hspll t ost + t rc (4) ec, rc t csd (2) intrc (1) ? intosc (2) t iobst (5) iofs intosc (3) lp, xt, hs t ost (5) osts hspll t ost + t rc (4) ec, rc t csd (2) intrc (1) ? intosc (2) none iofs none (sleep mode) lp, xt, hs t ost (4) osts hspll t ost + t rc (4) ec, rc t csd (2) intrc (1) ? intosc (2) t iobst (5) iofs note 1: in this instance, refers specifically to the 31 khz intrc clock source. 2: t csd (parameter 38) is a required delay when waking from sleep and all idle modes and runs concurrently with any other required delays (see section 3.4 ?idle modes? ). 3: includes both the intosc 8 mhz source and postscaler derived frequencies. 4: t ost is the oscillator start-up timer (parameter 32). t rc is the pll lock-out timer (parameter f12); it is also designated as t pll . 5: execution continues during t iobst (parameter 39), the intosc stabilization period.
? 2004 microchip technology inc. preliminary ds39625b-page 41 pic18f2585/2680/4585/4680 4.0 reset the pic18f2585/2680/4585/4680 devices differentiate between various kinds of reset: a) power-on reset (por) b) mclr reset during normal operation c) mclr reset during power managed modes d) watchdog timer (wdt) reset (during execution) e) programmable brown-out reset (bor) f) reset instruction g) stack full reset h) stack underflow reset this section discusses resets generated by mclr , por and bor and covers the operation of the various start-up timers. stack reset events are covered in section 5.1.2.4 ?stack full and underflow resets? . wdt resets are covered in section 24.2 ?watchdog timer (wdt)? . a simplified block diagram of the on-chip reset circuit is shown in figure 4-1. 4.1 rcon register device reset events are tracked through the rcon register (register 4-1). the lower five bits of the register indicate that a specific reset event has occurred. in most cases, these bits can only be cleared by the event and must be set by the application after the event. the state of these flag bits, taken together, can be read to indicate the type of reset that just occurred. this is described in more detail in section 4.6 ?reset state of registers? . the rcon register also has control bits for setting interrupt priority (ipen) and software control of the bor (sboren). interrupt priority is discussed in section 9.0 ?interrupts? . bor is covered in section 4.4 ?brown-out reset (bor)? . figure 4-1: simplified block diagram of on-chip reset circuit s r q external reset mclr v dd osc1 wdt time-out v dd rise detect ost/pwrt intrc (1) por pulse ost 10-bit ripple counter pwrt chip_reset 11-bit ripple counter enable ost (2) enable pwrt note 1: this is the intrc source from the internal oscillator bl ock and is separate from the rc oscillator of the clki pin. 2: see table 4-2 for time-out situations. brown-out reset boren reset instruction stack pointer stack full/underflow reset sleep ( )_idle 1024 cycles 65.5 ms 32 s mclre
pic18f2585/2680/4585/4680 ds39625b-page 42 preliminary ? 2004 microchip technology inc. register 4-1: rcon: reset control re gister r/w-0 r/w-1 (1) u-0 r/w-1 r-1 r-1 r/w-0 (2) r/w-0 ipen sboren ?ri to pd por bor bit 7 bit 0 bit 7 ipen: interrupt priority enable bit 1 = enable priority levels on interrupts 0 = disable priority levels on interrupts (16cxxx compatibility mode) bit 6 sboren: bor software enable bit (1) if boren1:boren0 = 01 : 1 = bor is enabled 0 = bor is disabled if boren1:boren0 = 00 , 10 or 11 : bit is disabled and read as ? 0 ?. bit 5 unimplemented: read as ? 0 ? bit 4 ri : reset instruction flag bit 1 = the reset instruction was not executed (set by firmware only) 0 = the reset instruction was executed causing a device reset (must be set in software after a brown-out reset occurs) bit 3 to : watchdog time-out flag bit 1 = set by power-up, clrwdt instruction or sleep instruction 0 = a wdt time-out occurred bit 2 pd : power-down detection flag bit 1 = set by power-up or by the clrwdt instruction 0 = set by execution of the sleep instruction bit 1 por : power-on reset status bit (2) 1 = a power-on reset has not occurred (set by firmware only) 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = a brown-out reset has not occurred (set by firmware only) 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) note 1: if sboren is enabled, its reset state is ? 1 ?; otherwise, it is ? 0 ?. 2: the actual reset value of por is determined by the type of device reset. see the notes following this register and section 4.6 ?reset state of registers? for additional information. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note 1: it is recommended that the por bit be set after a power-on reset has been detected so that subsequent power-on resets may be detected. 2: brown-out reset is said to have occurred when bor is ? 0 ? and por is ? 1 ? (assuming that por was set to ? 1 ? by software immediately after por).
? 2004 microchip technology inc. preliminary ds39625b-page 43 pic18f2585/2680/4585/4680 4.2 master clear reset (mclr ) the mclr pin provides a method for triggering an external reset of the device. a reset is generated by holding the pin low. these devices have a noise filter in the mclr reset path which detects and ignores small pulses. the mclr pin is not driven low by any internal resets, including the wdt. in pic18f2585/2680/4585/4680 devices, the mclr input can be disabled with the mclre configuration bit. when mclr is disabled, the pin becomes a digital input. see section 10.5 ?porte, trise and late registers? for more information. 4.3 power-on reset (por) a power-on reset pulse is generated on-chip whenever v dd rises above a certain threshold. this allows the device to start in the initialized state when v dd is adequate for operation. to take advantage of the por circuitry, tie the mclr pin through a resistor (1 k ? to 10 k ? ) to v dd . this will eliminate external rc components usually needed to create a power-on reset delay. a minimum rise rate for v dd is specified (parameter d004). for a slow rise time, see figure 4-2. when the device starts normal operation (i.e., exits the reset condition), device operating parameters (voltage, frequency, temperature, etc.) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating conditions are met. por events are captured by the por bit (rcon<1>). the state of the bit is set to ? 0 ? whenever a por occurs; it does not change for any other reset event. por is not reset to ? 1 ? by any hardware event. to capture multiple events, the user manually resets the bit to ? 1 ? in software following any por. figure 4-2: external power-on reset circuit (for slow v dd power-up) note 1: external power-on reset circuit is required only if the v dd power-up slope is too slow. the diode d helps discharge the capacitor quickly when v dd powers down. 2: r < 40 k ? is recommended to make sure that the voltage drop across r does not violate the device?s electric al specification. 3: r1 1 k ? will limit any current flowing into mclr from external capacitor c, in the event of mclr /v pp pin breakdown, due to electro- static discharge (esd) or electrical overstress (eos). c r1 r d v dd mclr pic18fxxxx v dd
pic18f2585/2680/4585/4680 ds39625b-page 44 preliminary ? 2004 microchip technology inc. 4.4 brown-out reset (bor) pic18f2585/2680/4585/4680 devices implement a bor circuit that provides the user with a number of configura- tion and power-saving options. the bor is controlled by the borv1:borv0 and boren1:boren0 configura- tion bits. there are a total of four bor configurations which are summarized in table 4-1. the bor threshold is set by the borv1:borv0 bits. if bor is enabled (any values of boren1:boren0, except ? 00 ?), any drop of v dd below v bor (parameter d005) for greater than t bor (parameter 35) will reset the device. a reset may or may not occur if v dd falls below v bor for less than t bor . the chip will remain in brown-out reset until v dd rises above v bor . if the power-up timer is enabled, it will be invoked after v dd rises above v bor ; it then will keep the chip in reset for an additional time delay, t pwrt (parameter 33). if v dd drops below v bor while the power-up timer is running, the chip will go back into a brown-out reset and the power-up timer will be initialized. once v dd rises above v bor , the power-up timer will execute the additional time delay. bor and the power-on timer (pwrt) are independently configured. enabling bor reset does not automatically enable the pwrt. 4.4.1 software enabled bor when boren1:boren0 = 01 , the bor can be enabled or disabled by the user in software. this is done with the control bit, sboren (rcon<6>). setting sboren enables the bor to function as previously described. clearing sboren disables the bor entirely. the sboren bit operates only in this mode; otherwise it is read as ? 0 ?. placing the bor under software control gives the user the additional flexibility of tailoring the application to its environment without having to reprogram the device to change bor configuration. it also allows the user to tailor device power consumption in software by elimi- nating the incremental current that the bor consumes. while the bor current is typically very small, it may have some impact in low-power applications. 4.4.2 detecting bor when bor is enabled, the bor bit always resets to ? 0 ? on any bor or por event. this makes it difficult to determine if a bor event has occurred just by reading the state of bor alone. a more reliable method is to simultaneously check the state of both por and bor . this assumes that the por bit is reset to ? 1 ? in software immediately after any por event. if bor is ? 0 ? while por is ? 1 ?, it can be reliably assumed that a bor event has occurred. 4.4.3 disabling bor in sleep mode when boren1:boren0 = 10 , the bor remains under hardware control and operates as previously described. whenever the device enters sleep mode, however, the bor is automatically disabled. when the device returns to any other operating mode, bor is automatically re-enabled. this mode allows for applications to recover from brown-out situations, while actively executing code, when the device requires bor protection the most. at the same time, it saves additional power in sleep mode by eliminating the small incremental bor current. table 4-1: bor configurations note: even when bor is under software control, the bor reset voltage level is still set by the borv1:borv0 configuration bits. it cannot be changed in software. bor configuration status of sboren (rcon<6>) bor operation boren1 boren0 00 unavailable bor disabled; must be enabled by reprogramming the configuration bits. 01 available bor enabled in software; operation controlled by sboren. 10 unavailable bor enabled in hardware in run and idle modes, disabled during sleep mode. 11 unavailable bor enabled in hardware; must be disabled by reprogramming the configuration bits.
? 2004 microchip technology inc. preliminary ds39625b-page 45 pic18f2585/2680/4585/4680 4.5 device reset timers pic18f2585/2680/4585/4680 devices incorporate three separate on-chip timers that help regulate the power-on reset process. their main function is to ensure that the device clock is stable before code is executed. these timers are:  power-up timer (pwrt)  oscillator start-up timer (ost)  pll lock time-out 4.5.1 power-up timer (pwrt) the power-up timer (pwrt) of pic18f2585/2680/ 4585/4680 devices is an 11-bit counter which uses the intrc source as the clock input. this yields an approximate time interval of 2048 x 32 s=65.6ms. while the pwrt is counting, the device is held in reset. the power-up time delay depends on the intrc clock and will vary from chip to chip due to temperature and process variation. see dc parameter 33 for details. the pwrt is enabled by clearing the pwrten configuration bit. 4.5.2 oscillator start-up timer (ost) the oscillator start-up timer (ost) provides a 1024 oscillator cycle (from osc1 input) delay after the pwrt delay is over (parameter 33). this ensures that the crystal oscillator or resonator has started and stabilized. the ost time-out is invoked only for xt, lp, hs and hspll modes and only on power-on reset or on exit from most power managed modes. 4.5.3 pll lock time-out with the pll enabled in its pll mode, the time-out sequence following a power-on reset is slightly different from other oscillator modes. a separate timer is used to provide a fixed time-out that is sufficient for the pll to lock to the main oscillator frequency. this pll lock time-out (t pll ) is typically 2 ms and follows the oscillator start-up time-out. 4.5.4 time-out sequence on power-up, the time-out sequence is as follows: 1. after the por pulse has cleared, pwrt time-out is invoked (if enabled). 2. then, the ost is activated. the total time-out will vary based on oscillator configu- ration and the status of the pwrt. figure 4-3, figure 4-4, figure 4-5, figure 4-6 and figure 4-7 all depict time-out sequences on power-up, with the power-up timer enabled and the device operating in hs oscillator mode. figures 4-3 through 4-6 also apply to devices operating in xt or lp modes. for devices in rc mode and with the pwrt disabled, on the other hand, there will be no time-out at all. since the time-outs occur from the por pulse, if mclr is kept low long enough, all time-outs will expire. bringing mclr high will begin execution immediately (figure 4-5). this is useful for testing purposes or to synchronize more than one pic18fxxxx device operating in parallel. table 4-2: time-out in various situations oscillator configuration power-up (2) and brown-out exit from power managed mode pwrten = 0 pwrten = 1 hspll 66 ms (1) + 1024 t osc + 2 ms (2) 1024 t osc + 2 ms (2) 1024 t osc + 2 ms (2) hs, xt, lp 66 ms (1) + 1024 t osc 1024 t osc 1024 t osc ec, ecio 66 ms (1) ?? rc, rcio 66 ms (1) ?? intio1, intio2 66 ms (1) ?? note 1: 66 ms (65.5 ms) is the nominal power-up timer (pwrt) delay. 2: 2 ms is the nominal time required for the pll to lock.
pic18f2585/2680/4585/4680 ds39625b-page 46 preliminary ? 2004 microchip technology inc. figure 4-3: time-out sequence on power-up (mclr tied to v dd , v dd rise < t pwrt ) figure 4-4: time-out sequence on power-up (mclr not tied to v dd ): case 1 figure 4-5: time-out sequence on power-up (mclr not tied to v dd ): case 2 t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost
? 2004 microchip technology inc. preliminary ds39625b-page 47 pic18f2585/2680/4585/4680 figure 4-6: slow rise time (mclr tied to v dd , v dd rise > t pwrt ) figure 4-7: time-out sequence on por w/pll enabled (mclr tied to v dd ) v dd mclr internal por pwrt time-out ost time-out internal reset 0v 1v 5v t pwrt t ost t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset pll time-out t pll note: t ost = 1024 clock cycles. t pll 2 ms max. first three stages of the pwrt timer.
pic18f2585/2680/4585/4680 ds39625b-page 48 preliminary ? 2004 microchip technology inc. 4.6 reset state of registers most registers are unaffected by a reset. their status is unknown on por and unchanged by all other resets. the other registers are forced to a ?reset state? depending on the type of reset that occurred. most registers are not affected by a wdt wake-up, since this is viewed as the resumption of normal operation. status bits from the rcon register, ri , to , pd , por and bor , are set or cleared differently in different reset situations, as indicated in table 4-3. these bits are used in software to determine the nature of the reset. table 4-4 describes the reset states for all of the special function registers. these are categorized by power-on and brown-out resets, master clear and wdt resets and wdt wake-ups. table 4-3: status bits, their significance and the initialization condition for rcon register condition program counter rcon register stkptr register sboren ri to pd por bor stkful stkunf power-on reset 0000h 1 11100 0 0 reset instruction 0000h u (2) 0uuuu u u brown-out 0000h u (2) 111u0 u u mclr during power managed run modes 0000h u (2) u1uuu u u mclr during power managed idle modes and sleep mode 0000h u (2) u10uu u u wdt time-out during full power or power managed run modes 0000h u (2) u0uuu u u mclr during full power execution 0000h u (2) uuuuu u u stack full reset (stvren = 1 ) 0000h u (2) uuuuu 1 u stack underflow reset (stvren = 1 ) 0000h u (2) uuuuu u 1 stack underflow error (not an actual reset, stvren = 0 ) 0000h u (2) uuuuu u 1 wdt time-out during power managed idle or sleep modes pc + 2 u (2) u00uu u u interrupt exit from power managed modes pc + 2 (1) u (2) uu0uu u u legend: u = unchanged note 1: when the wake-up is due to an interrupt and the gieh or giel bits are set, the pc is loaded with the interrupt vector (008h or 0018h). 2: reset state is ? 1 ? for por and unchanged for all other resets when software bor is enabled (boren1:boren0 configuration bits = 01 and sboren = 1 ); otherwise, the reset state is ? 0 ?.
? 2004 microchip technology inc. preliminary ds39625b-page 49 pic18f2585/2680/4585/4680 table 4-4: initialization conditions for all registers register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt tosu 2585 2680 4585 4680 ---0 0000 ---0 0000 ---0 uuuu (3) tosh 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu (3) tosl 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu (3) stkptr 2585 2680 4585 4680 00-0 0000 uu-0 0000 uu-u uuuu (3) pclatu 2585 2680 4585 4680 ---0 0000 ---0 0000 ---u uuuu pclath 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu pcl 2585 2680 4585 4680 0000 0000 0000 0000 pc + 2 (2) tblptru 2585 2680 4585 4680 --00 0000 --00 0000 --uu uuuu tblptrh 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu tblptrl 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu tablat 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu prodh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu prodl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu intcon 2585 2680 4585 4680 0000 000x 0000 000u uuuu uuuu (1) intcon2 2585 2680 4585 4680 1111 -1-1 1111 -1-1 uuuu -u-u (1) intcon3 2585 2680 4585 4680 11-0 0-00 11-0 0-00 uu-u u-uu (1) indf0 2585 2680 4585 4680 n/a n/a n/a postinc0 2585 2680 4585 4680 n/a n/a n/a postdec0 2585 2680 4585 4680 n/a n/a n/a preinc0 2585 2680 4585 4680 n/a n/a n/a plusw0 2585 2680 4585 4680 n/a n/a n/a fsr0h 2585 2680 4585 4680 ---- 0000 ---- 0000 ---- uuuu fsr0l 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu wreg 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu indf1 2585 2680 4585 4680 n/a n/a n/a postinc1 2585 2680 4585 4680 n/a n/a n/a postdec1 2585 2680 4585 4680 n/a n/a n/a preinc1 2585 2680 4585 4680 n/a n/a n/a plusw1 2585 2680 4585 4680 n/a n/a n/a fsr1h 2585 2680 4585 4680 ---- 0000 ---- 0000 ---- uuuu fsr1l 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f2585/2680/4585/4680 ds39625b-page 50 preliminary ? 2004 microchip technology inc. bsr 2585 2680 4585 4680 ---- 0000 ---- 0000 ---- uuuu indf2 2585 2680 4585 4680 n/a n/a n/a postinc2 2585 2680 4585 4680 n/a n/a n/a postdec2 2585 2680 4585 4680 n/a n/a n/a preinc2 2585 2680 4585 4680 n/a n/a n/a plusw2 2585 2680 4585 4680 n/a n/a n/a fsr2h 2585 2680 4585 4680 ---- 0000 ---- 0000 ---- uuuu fsr2l 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu status 2585 2680 4585 4680 ---x xxxx ---u uuuu ---u uuuu tmr0h 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu tmr0l 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu t0con 2585 2680 4585 4680 1111 1111 1111 1111 uuuu uuuu osccon 2585 2680 4585 4680 0100 q000 0100 00q0 uuuu uuqu hlvdcon 2585 2680 4585 4680 0-00 0101 0-00 0101 0-uu uuuu wdtcon 2585 2680 4585 4680 ---- ---0 ---- ---0 ---- ---u rcon (4) 2585 2680 4585 4680 0q-1 11q0 0q-q qquu uq-u qquu tmr1h 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu tmr1l 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu t1con 2585 2680 4585 4680 0000 0000 u0uu uuuu uuuu uuuu tmr2 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu pr2 2585 2680 4585 4680 1111 1111 1111 1111 1111 1111 t2con 2585 2680 4585 4680 -000 0000 -000 0000 -uuu uuuu sspbuf 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu sspadd 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu sspstat 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu sspcon1 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu sspcon2 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu adresh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu adresl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu adcon0 2585 2680 4585 4680 --00 0000 --00 0000 --uu uuuu adcon1 2585 2680 4585 4680 --00 0qqq --00 0qqq --uu uuuu adcon2 2585 2680 4585 4680 0-00 0000 0-00 0000 u-uu uuuu table 4-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2004 microchip technology inc. preliminary ds39625b-page 51 pic18f2585/2680/4585/4680 ccpr1h 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu ccpr1l 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu ccp1con 2585 2680 4585 4680 --00 0000 --00 0000 --uu uuuu eccpr1h 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu eccpr1l 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu eccp1con 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu baudcon 2585 2680 4585 4680 01-0 0-00 01-0 0-00 --uu uuuu eccp1del 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu eccp1as 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu cvrcon 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu cmcon 2585 2680 4585 4680 0000 0111 0000 0111 uuuu uuuu tmr3h 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu tmr3l 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu t3con 2585 2680 4585 4680 0000 0000 uuuu uuuu uuuu uuuu spbrgh 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu spbrg 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu rcreg 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu txreg 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu txsta 2585 2680 4585 4680 0000 0010 0000 0010 uuuu uuuu rcsta 2585 2680 4585 4680 0000 000x 0000 000x uuuu uuuu eeadrh 2585 2680 4585 4680 ---- --00 ---- --00 ---- --uu eeadr 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu eedata 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu eecon2 2585 2680 4585 4680 0000 0000 0000 0000 0000 0000 eecon1 2585 2680 4585 4680 xx-0 x000 uu-0 u000 uu-0 u000 ipr3 2585 2680 4585 4680 1111 1111 1111 1111 uuuu uuuu pir3 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu pie3 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu ipr2 2585 2680 4585 4680 11-1 1111 11-1 1111 uu-u uuuu 2585 2680 4585 4680 1--1 111- 1--1 111- u--u uuu- pir2 2585 2680 4585 4680 00-0 0000 00-0 0000 uu-u uuuu (1) 2585 2680 4585 4680 0--0 000- 0--0 000- u--u uuu- (1) table 4-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f2585/2680/4585/4680 ds39625b-page 52 preliminary ? 2004 microchip technology inc. pie2 2585 2680 4585 4680 00-0 0000 00-0 0000 uu-u uuuu 2585 2680 4585 4680 0--0 000- 0--0 000- u--u uuu- ipr1 2585 2680 4585 4680 1111 1111 1111 1111 uuuu uuuu 2585 2680 4585 4680 -111 1111 -111 1111 -uuu uuuu pir1 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu (1) 2585 2680 4585 4680 -000 0000 -000 0000 -uuu uuuu pie1 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu 2585 2680 4585 4680 -000 0000 -000 0000 -uuu uuuu osctune 2585 2680 4585 4680 --00 0000 --00 0000 --uu uuuu trise 2585 2680 4585 4680 0000 -111 0000 -111 uuuu -uuu trisd 2585 2680 4585 4680 1111 1111 1111 1111 uuuu uuuu trisc 2585 2680 4585 4680 1111 1111 1111 1111 uuuu uuuu trisb 2585 2680 4585 4680 1111 1111 1111 1111 uuuu uuuu trisa (5) 2585 2680 4585 4680 1111 1111 (5) 1111 1111 (5) uuuu uuuu (5) late 2585 2680 4585 4680 ---- -xxx ---- -uuu ---- -uuu latd 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu latc 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu latb 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu lata (5) 2585 2680 4585 4680 xxxx xxxx (5) uuuu uuuu (5) uuuu uuuu (5) porte 2585 2680 4585 4680 ---- x000 ---- x000 ---- uuuu portd 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu portc 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu portb 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu porta (5) 2585 2680 4585 4680 xx0x 0000 (5) uu0u 0000 (5) uuuu uuuu (5) ecancon 2585 2680 4585 4680 0001 0000 0001 0000 uuuu uuuu txerrcnt 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu rxerrcnt 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu comstat 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu ciocon 2585 2680 4585 4680 --00 ---- --00 ---- --uu ---- brgcon3 2585 2680 4585 4680 00-- -000 00-- -000 uu-- -uuu brgcon2 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu brgcon1 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu table 4-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2004 microchip technology inc. preliminary ds39625b-page 53 pic18f2585/2680/4585/4680 cancon 2585 2680 4585 4680 1000 000- 1000 000- uuuu uuu- canstat 2585 2680 4585 4680 100- 000- 100- 000- uuu- uuu- rxb0d7 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d6 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d5 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d4 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d3 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d2 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d1 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d0 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb0dlc 2585 2680 4585 4680 -xxx xxxx -uuu uuuu -uuu uuuu rxb0eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb0eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb0sidl 2585 2680 4585 4680 xxxx x-xx uuuu u-uu uuuu u-uu rxb0sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb0con 2585 2680 4585 4680 000- 0000 000- 0000 uuu- uuuu rxb1d7 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d6 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d5 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d4 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d3 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d2 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d1 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d0 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb1dlc 2585 2680 4585 4680 -xxx xxxx -uuu uuuu -uuu uuuu rxb1eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb1eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb1sidl 2585 2680 4585 4680 xxxx x-xx uuuu u-uu uuuu u-uu rxb1sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxb1con 2585 2680 4585 4680 000- 0000 000- 0000 uuu- uuuu txb0d7 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb0d6 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu table 4-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f2585/2680/4585/4680 ds39625b-page 54 preliminary ? 2004 microchip technology inc. txb0d5 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb0d4 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb0d3 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb0d2 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb0d1 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb0d0 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb0dlc 2585 2680 4585 4680 -x-- xxxx -u-- uuuu -u-- uuuu txb0eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb0eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu txb0sidl 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu txb0sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb0con 2585 2680 4585 4680 0000 0-00 0000 0-00 uuuu u-uu txb1d7 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb1d6 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb1d5 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb1d4 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb1d3 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb1d2 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb1d1 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb1d0 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb1dlc 2585 2680 4585 4680 -x-- xxxx -u-- uuuu -u-- uuuu txb1eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb1eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb1sidl 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- uu-u txb1sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu txb1con 2585 2680 4585 4680 0000 0-00 0000 0-00 uuuu u-uu txb2d7 2585 2680 4585 4680 xxxx xxxx uuuu uuuu 0uuu uuuu txb2d6 2585 2680 4585 4680 xxxx xxxx uuuu uuuu 0uuu uuuu txb2d5 2585 2680 4585 4680 xxxx xxxx uuuu uuuu 0uuu uuuu txb2d4 2585 2680 4585 4680 xxxx xxxx uuuu uuuu 0uuu uuuu txb2d3 2585 2680 4585 4680 xxxx xxxx uuuu uuuu 0uuu uuuu txb2d2 2585 2680 4585 4680 xxxx xxxx uuuu uuuu 0uuu uuuu table 4-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2004 microchip technology inc. preliminary ds39625b-page 55 pic18f2585/2680/4585/4680 txb2d1 2585 2680 4585 4680 xxxx xxxx uuuu uuuu 0uuu uuuu txb2d0 2585 2680 4585 4680 xxxx xxxx uuuu uuuu 0uuu uuuu txb2dlc 2585 2680 4585 4680 -x-- xxxx -u-- uuuu -u-- uuuu txb2eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb2eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu txb2sidl 2585 2680 4585 4680 xxxx x-xx uuuu u-uu -uuu uuuu txb2sidh 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu txb2con 2585 2680 4585 4680 0000 0-00 0000 0-00 uuuu u-uu rxm1eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxm1eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxm1sidl 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxm1sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxm0eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxm0eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxm0sidl 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxm0sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf5eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf5eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf5sidl 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxf5sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf4eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf4eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf4sidl 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxf4sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf3eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf3eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf3sidl 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxf3sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf2eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf2eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf2sidl 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxf2sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu table 4-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f2585/2680/4585/4680 ds39625b-page 56 preliminary ? 2004 microchip technology inc. rxf1eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf1eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf1sidl 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxf1sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf0eidl 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf0eidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf0sidl 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxf0sidh 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b5d7 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b5d6 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b5d5 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b5d4 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b5d3 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b5d2 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b5d1 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b5d0 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b5dlc (6) 2585 2680 4585 4680 -xxx xxxx -uuu uuuu -uuu uuuu b5eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b5eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b5sidl (6) 2585 2680 4585 4680 xxxx x-xx uuuu u-uu uuuu u-uu b5sidh (6) 2585 2680 4585 4680 xxxx x-xx uuuu u-uu uuuu u-uu b5con (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu b4d7 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b4d6 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b4d5 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b4d4 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b4d3 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b4d2 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b4d1 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b4d0 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b4dlc (6) 2585 2680 4585 4680 -xxx xxxx -uuu uuuu -uuu uuuu b4eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu table 4-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2004 microchip technology inc. preliminary ds39625b-page 57 pic18f2585/2680/4585/4680 b4eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b4sidl (6) 2585 2680 4585 4680 xxxx x-xx uuuu u-uu uuuu u-uu b4sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b4con (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu b3d7 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b3d6 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b3d5 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b3d4 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b3d3 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b3d2 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b3d1 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b3d0 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b3dlc (6) 2585 2680 4585 4680 -xxx xxxx -uuu uuuu -uuu uuuu b3eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b3eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b3sidl (6) 2585 2680 4585 4680 xxxx x-xx uuuu u-uu uuuu u-uu b3sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b3con (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu b2d7 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b2d6 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b2d5 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b2d4 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b2d3 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b2d2 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b2d1 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b2d0 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b2dlc (6) 2585 2680 4585 4680 -xxx xxxx -uuu uuuu -uuu uuuu b2eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b2eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b2sidl (6) 2585 2680 4585 4680 xxxx x-xx uuuu u-uu uuuu u-uu b2sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu table 4-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f2585/2680/4585/4680 ds39625b-page 58 preliminary ? 2004 microchip technology inc. b2con (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu b1d7 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b1d6 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b1d5 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b1d4 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b1d3 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b1d2 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b1d1 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b1d0 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b1dlc (6) 2585 2680 4585 4680 -xxx xxxx -uuu uuuu -uuu uuuu b1eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b1eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b1sidl (6) 2585 2680 4585 4680 xxxx x-xx uuuu u-uu uuuu u-uu b1sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b1con (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu b0d7 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b0d6 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b0d5 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b0d4 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b0d3 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b0d2 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b0d1 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b0d0 (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b0dlc (6) 2585 2680 4585 4680 -xxx xxxx -uuu uuuu -uuu uuuu b0eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b0eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b0sidl (6) 2585 2680 4585 4680 xxxx x-xx uuuu u-uu uuuu u-uu b0sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu b0con (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu txbie (6) 2585 2680 4585 4680 ---0 00-- ---u uu-- ---u uu-- bie0 (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu table 4-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2004 microchip technology inc. preliminary ds39625b-page 59 pic18f2585/2680/4585/4680 bsel0 (6) 2585 2680 4585 4680 0000 00-- 0000 00-- uuuu uu-- msel3 (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu msel2 (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu msel1 (6) 2585 2680 4585 4680 0000 0101 0000 0101 uuuu uuuu msel0 (6) 2585 2680 4585 4680 0101 0000 0101 0000 uuuu uuuu sdflc (6) 2585 2680 4585 4680 ---0 0000 ---0 0000 -u-- uuuu rxfcon1 (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu rxfcon0 (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu rxfbcon7 (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu rxfbcon6 (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu rxfbcon5 (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu rxfbcon4 (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu rxfbcon3 (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu rxfbcon2 (6) 2585 2680 4585 4680 0001 0001 0001 0001 uuuu uuuu rxfbcon1 (6) 2585 2680 4585 4680 0001 0001 0001 0001 uuuu uuuu rxfbcon0 (6) 2585 2680 4585 4680 0000 0000 0000 0000 uuuu uuuu rxf15eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf15eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf15sidl (6) 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxf15sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf14eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf14eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf14sidl (6) 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxf14sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf13eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf13eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf13sidl (6) 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxf13sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf12eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf12eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf12sidl (6) 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu table 4-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f2585/2680/4585/4680 ds39625b-page 60 preliminary ? 2004 microchip technology inc. rxf12sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf11eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf11eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf11sidl (6) 2585 2680 4585 4680 xxx- x-xx uuu- u-uu uuu- u-uu rxf11sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu uuuu uuuu rxf10eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf10eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf10sidl (6) 2585 2680 4585 4680 xxx- x-xx uuu- u-uu -uuu uuuu rxf10sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf9eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf9eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf9sidl (6) 2585 2680 4585 4680 xxx- x-xx uuu- u-uu -uuu uuuu rxf9sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf8eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf8eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf8sidl (6) 2585 2680 4585 4680 xxx- x-xx uuu- u-uu -uuu uuuu rxf8sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf7eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf7eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf7sidl (6) 2585 2680 4585 4680 xxx- x-xx uuu- u-uu -uuu uuuu rxf7sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf6eidl (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf6eidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu rxf6sidl (6) 2585 2680 4585 4680 xxx- x-xx uuu- u-uu -uuu uuuu rxf6sidh (6) 2585 2680 4585 4680 xxxx xxxx uuuu uuuu -uuu uuuu table 4-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2004 microchip technology inc. preliminary ds39625b-page 61 pic18f2585/2680/4585/4680 5.0 memory organization there are three types of memory in pic18 enhanced microcontroller devices:  program memory  data ram  data eeprom as harvard architecture devices, the data and program memories use separate busses; this allows for con- current access of the two memory spaces. the data eeprom, for practical purposes, can be regarded as a peripheral device, since it is addressed and accessed through a set of control registers. additional detailed information on the operation of the flash program memory is provided in section 6.0 ?flash program memory? . data eeprom is discussed separately in section 7.0 ?data eeprom memory? . 5.1 program memory organization pic18 microcontrollers implement a 21-bit program counter, which is capable of addressing a 2-mbyte program memory space. accessing a location between the upper boundary of the physically implemented memory and the 2-mbyte address will return all ? 0 ?s (a nop instruction). the pic18f2585 and pic18f4585 each have 48 kbytes of flash memory and can store up to 24,576 single-word instructions. the pic18f2680 and pic18f4680 each have 64 kbytes of flash memory and can store up to 32,768 single-word instructions. pic18 devices have two interrupt vectors. the reset vector address is at 0000h and the interrupt vector addresses are at 0008h and 0018h. the program memory maps for pic18fx585 and pic18fx680 devices are shown in figure 5-1. figure 5-1: program memory map and stack for pic18f2585/2680/4585/4680 devices pc<20:0> stack level 1 ? stack level 31 reset vector low priority interrupt vector ? ? call,rcall,return retfie,retlw 21 0000h 0018h on-chip program memory high priority interrupt vector 0008h user memory space 1fffffh c000h bfffh read ? 0 ? 200000h pc<20:0> stack level 1 ? stack level 31 reset vector low priority interrupt vector ? ? call,rcall,return retfie,retlw 21 0000h 0018h 10000h ffffh on-chip program memory high priority interrupt vector 0008h user memory space read ? 0 ? 1fffffh 200000h pic18x585 pic18fx680
pic18f2585/2680/4585/4680 ds39625b-page 62 preliminary ? 2004 microchip technology inc. 5.1.1 program counter the program counter (pc) specifies the address of the instruction to fetch for execution. the pc is 21 bits wide and is contained in three separate 8-bit registers. the low byte, known as the pcl register, is both readable and writable. the high byte, or pch register, contains the pc<15:8> bits; it is not directly readable or writable. updates to the pch register are performed through the pclath register. the upper byte is called pcu. this register contains the pc<20:16> bits; it is also not directly readable or writable. updates to the pcu register are performed through the pclatu register. the contents of pclath and pclatu are transferred to the program counter by any operation that writes pcl. similarly, the upper two bytes of the program counter are transferred to pclath and pclatu by an operation that reads pcl. this is useful for computed offsets to the pc (see section 5.1.4.1 ?computed goto? ). the pc addresses bytes in the program memory. to prevent the pc from becoming misaligned with word instructions, the least significant bit of pcl is fixed to a value of ? 0 ?. the pc increments by 2 to address sequential instructions in the program memory. the call , rcall and goto program branch instructions write to the program counter directly. for these instructions, the contents of pclath and pclatu are not transferred to the program counter. 5.1.2 return address stack the return address stack allows any combination of up to 31 program calls and interrupts to occur. the pc is pushed onto the stack when a call or rcall instruc- tion is executed or an interrupt is acknowledged. the pc value is pulled off the stack on a return, retlw or a retfie instruction. pclatu and pclath are not affected by any of the return or call instructions. the stack operates as a 31-word by 21-bit ram and a 5-bit stack pointer, stkptr. the stack space is not part of either program or data space. the stack pointer is readable and writable and the address on the top of the stack is readable and writable through the top-of-stack special file registers. data can also be pushed to, or popped from the stack, using these registers. a call type instruction causes a push onto the stack; the stack pointer is first incremented and the location pointed to by the stack pointer is written with the contents of the pc (already pointing to the instruction following the call ). a return type instruction causes a pop from the stack; the contents of the location pointed to by the stkptr are transferred to the pc and then the stack pointer is decremented. the stack pointer is initialized to ? 00000 ? after all resets. there is no ram associated with the location corresponding to a stack pointer value of ? 00000 ?; this is only a reset value. status bits indicate if the stack is full or has overflowed or has underflowed. 5.1.2.1 top-of-stack access only the top of the return address stack (tos) is readable and writable. a set of three registers, tosu:tosh:tosl, hold the contents of the stack loca- tion pointed to by the stkptr register (figure 5-2). this allows users to implement a software stack if necessary. after a call , rcall or interrupt, the software can read the pushed value by reading the tosu:tosh:tosl registers. these values can be placed on a user defined software stack. at return time, the software can return these values to tosu:tosh:tosl and do a return. the user must disable the global interrupt enable bits while accessing the stack to prevent inadvertent stack corruption. figure 5-2: return address stack and associated registers 00011 001a34h 11111 11110 11101 00010 00001 00000 00010 return address stack <20:0> to p - o f - st a c k 000d58h tosl tosh tosu 34h 1ah 00h stkptr<4:0> top-of-stack registers stack pointer
? 2004 microchip technology inc. preliminary ds39625b-page 63 pic18f2585/2680/4585/4680 5.1.2.2 return stack pointer (stkptr) the stkptr register (register 5-1) contains the stack pointer value, the stkful (stack full) status bit and the stkunf (stack underflow) status bits. the value of the stack pointer can be 0 through 31. the stack pointer increments before values are pushed onto the stack and decrements after values are popped off the stack. on reset, the stack pointer value will be zero. the user may read and write the stack pointer value. this feature can be used by a real-time operating system (rtos) for return stack maintenance. after the pc is pushed onto the stack 31 times (without popping any values off the stack), the stkful bit is set. the stkful bit is cleared by software or by a por. the action that takes place when the stack becomes full depends on the state of the stvren (stack over- flow reset enable) configuration bit. (refer to section 24.1 ?configuration bits? for a description of the device configuration bits.) if stvren is set (default), the 31st push will push the (pc + 2) value onto the stack, set the stkful bit and reset the device. the stkful bit will remain set and the stack pointer will be set to zero. if stvren is cleared, the stkful bit will be set on the 31st push and the stack pointer will increment to 31. any additional pushes will not overwrite the 31st push and stkptr will remain at 31. when the stack has been popped enough times to unload the stack, the next pop will return a value of zero to the pc and sets the stkunf bit, while the stack pointer remains at zero. the stkunf bit will remain set until cleared by software or until a por occurs. 5.1.2.3 push and pop instructions since the top-of-stack is readable and writable, the ability to push values onto the stack and pull values off the stack without disturbing normal program execution is a desirable feature. the pic18 instruction set includes two instructions, push and pop , that permit the tos to be manipulated under software control. tosu, tosh and tosl can be modified to place data or a return address on the stack. the push instruction places the current pc value onto the stack. this increments the stack pointer and loads the current pc value onto the stack. the pop instruction discards the current tos by decre- menting the stack pointer. the previous value pushed onto the stack then becomes the tos value. register 5-1: stkptr: stack pointer register note: returning a value of zero to the pc on an underflow has the effect of vectoring the program to the reset vector, where the stack conditions can be verified and appropriate actions can be taken. this is not the same as a reset, as the contents of the sfrs are not affected. r/c-0 r/c-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 stkful (1) stkunf (1) ? sp4 sp3 sp2 sp1 sp0 bit 7 bit 0 bit 7 stkful: stack full flag bit (1) 1 = stack became full or overflowed 0 = stack has not become full or overflowed bit 6 stkunf: stack underflow flag bit (1) 1 = stack underflow occurred 0 = stack underflow did not occur bit 5 unimplemented: read as ? 0 ? bit 4-0 sp4:sp0: stack pointer location bits note 1: bit 7 and bit 6 are cleared by user software or by a por. legend: r = readable bit w = writable bit u = unimplemented c = clearable only bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 64 preliminary ? 2004 microchip technology inc. 5.1.2.4 stack full and underflow resets device resets on stack overflow and stack underflow conditions are enabled by setting the stvren bit in configuration register 4l. when stvren is set, a full or underflow will set the appropriate stkful or stkunf bit and then cause a device reset. when stvren is cleared, a full or underflow condition will set the appropriate stkful or stkunf bit, but not cause a device reset. the stkful or stkunf bits are cleared by the user software or a power-on reset. 5.1.3 fast register stack a fast register stack is provided for the status, wreg and bsr registers, to provide a ?fast return? option for interrupts. each stack is only one level deep and is neither readable nor writable. it is loaded with the current value of the corresponding register when the processor vectors for an interrupt. all interrupt sources will push values into the stack registers. the values in the registers are then loaded back into their associated registers, if the retfie, fast instruction is used to return from the interrupt. if both low and high priority interrupts are enabled, the stack registers cannot be used reliably to return from low priority interrupts. if a high priority interrupt occurs while servicing a low priority interrupt, the stack register values stored by the low priority interrupt will be overwritten. in these cases, users must save the key registers in software during a low priority interrupt. if interrupt priority is not used, all interrupts may use the fast register stack for returns from interrupt. if no inter- rupts are used, the fast register stack can be used to restore the status, wreg and bsr registers at the end of a subroutine call. to use the fast register stack for a subroutine call, a call label, fast instruction must be executed to save the status, wreg and bsr regis- ters to the fast register stack. a return, fast instruction is then executed to restore these registers from the fast register stack. example 5-1 shows a source code example that uses the fast register stack during a subroutine call and return. example 5-1: fast register stack code example 5.1.4 look-up tables in program memory there may be programming situations that require the creation of data structures, or look-up tables, in program memory. for pic18 devices, look-up tables can be implemented in two ways:  computed goto  table reads 5.1.4.1 computed goto a computed goto is accomplished by adding an offset to the program counter. an example is shown in example 5-2. a look-up table can be formed with an addwf pcl instruction and a group of retlw nn instructions. the w register is loaded with an offset into the table before executing a call to that table. the first instruction of the called routine is the addwf pcl instruction. the next instruction executed will be one of the retlw nn instructions, that returns the value ? nn ? to the calling function. the offset value (in wreg) specifies the number of bytes that the program counter should advance and should be multiples of 2 (lsb = 0 ). in this method, only one data byte may be stored in each instruction location and room on the return address stack is required. example 5-2: computed goto using an offset value 5.1.4.2 table reads and table writes a better method of storing data in program memory allows two bytes of data to be stored in each instruction location. look-up table data may be stored two bytes per program word by using table reads and writes. the table pointer (tblptr) register specifies the byte address and the table latch (tablat) register contains the data that is read from or written to program memory. data is transferred to or from program memory one byte at a time. table read and table write operations are discussed further in section 6.1 ?table reads and table writes? . call sub1, fast ;status, wreg, bsr ;saved in fast register ;stack ? ? sub1 ? ? return, fast ;restore values saved ;in fast register stack movf offset, w call table org nn00h table addwf pcl retlw nnh retlw nnh retlw nnh . . .
? 2004 microchip technology inc. preliminary ds39625b-page 65 pic18f2585/2680/4585/4680 5.2 pic18 instruction cycle 5.2.1 clocking scheme the microcontroller clock input, whether from an inter- nal or external source, is internally divided by four to generate four non-overlapping quadrature clocks (q1, q2, q3 and q4). internally, the program counter (pc) is incremented on every q1; the instruction is fetched from the program memory and latched into the instruc- tion register (ir) during q4. the instruction is decoded and executed during the following q1 through q4. the clocks and instruction execution flow are shown in figure 5-3. 5.2.2 instruction flow/pipelining an ?instruction cycle? consists of four q cycles: q1 through q4. the instruction fetch and execute are pipe- lined in such a manner that a fetch takes one instruction cycle, while the decode and execute take another instruction cycle. however, due to the pipelining, each instruction effectively executes in one cycle. if an instruction causes the program counter to change (e.g., goto ), then two cycles are required to complete the instruction (example 5-3). a fetch cycle begins with the program counter incrementing in q1. in the execution cycle, the fetched instruction is latched into the instruction register (ir) in cycle q1. this instruction is then decoded and executed during the q2, q3 and q4 cycles. data memory is read during q2 (operand read) and written during q4 (destination write). figure 5-3: clock/ instruction cycle example 5-3: instruction pipeline flow q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 q1 q2 q3 q4 pc osc2/clko (rc mode) pc pc + 2 pc + 4 fetch inst (pc) execute inst (pc ? 2) fetch inst (pc + 2) execute inst (pc) fetch inst (pc + 4) execute inst (pc + 2) internal phase clock note: all instructions are single cycle, except for any program branches. these take two cycles since the fetch instruction is ?flushed? from the pipeline while the new instruction is being fetched and then executed. t cy 0t cy 1t cy 2t cy 3t cy 4t cy 5 1. movlw 55h fetch 1 execute 1 2. movwf portb fetch 2 execute 2 3. bra sub_1 fetch 3 execute 3 4. bsf porta, bit3 (forced nop) fetch 4 flush ( nop ) 5. instruction @ address sub_1 fetch sub_1 execute sub_1
pic18f2585/2680/4585/4680 ds39625b-page 66 preliminary ? 2004 microchip technology inc. 5.2.3 instructions in program memory the program memory is addressed in bytes. instruc- tions are stored as two bytes or four bytes in program memory. the least significant byte of an instruction word is always stored in a program memory location with an even address (lsb = 0 ). to maintain alignment with instruction boundaries, the pc increments in steps of 2 and the lsb will always read ? 0 ? (see section 5.1.1 ?program counter? ). figure 5-4 shows an example of how instruction words are stored in the program memory. the call and goto instructions have the absolute program memory address embedded into the instruc- tion. since instructions are always stored on word boundaries, the data contained in the instruction is a word address. the word address is written to pc<20:1>, which accesses the desired byte address in program memory. instruction #2 in figure 5-4 shows how the instruction goto 0006h is encoded in the program memory. program branch instructions, which encode a relative address offset, operate in the same manner. the offset value stored in a br anch instruction represents the number of single-word instructions that the pc will be offset by. section 25.0 ?instruction set summary? provides further details of the instruction set. figure 5-4: instructions in program memory 5.2.4 two-word instructions the standard pic18 instruction set has four two-word instructions: call , movff , goto and lsfr . in all cases, the second word of the instructions always has ? 1111 ? as its four most significant bits; the other 12 bits are literal data, usually a data memory address. the use of ? 1111 ? in the 4 msbs of an instruction specifies a special form of nop . if the instruction is executed in proper sequence ? immediately after the first word ? the data in the second word is accessed and used by the instruction sequence. if the first word is skipped for some reason and the second word is executed by itself, a nop is executed instead. this is necessary for cases when the two-word instruction is preceded by a conditional instruction that changes the pc. example 5-4 shows how this works. example 5-4: two-word instructions word address lsb = 1 lsb = 0 program memory byte locations 000000h 000002h 000004h 000006h instruction 1: movlw 055h 0fh 55h 000008h instruction 2: goto 0006h efh 03h 00000ah f0h 00h 00000ch instruction 3: movff 123h, 456h c1h 23h 00000eh f4h 56h 000010h 000012h 000014h note: see section 5.5 ?program memory and the extended instruction set? for information on two-word instructions in the extended instruction set. case 1: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; no, skip this word 1111 0100 0101 0110 ; execute this word as a nop 0010 0100 0000 0000 addwf reg3 ; continue code case 2: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; yes, execute this word 1111 0100 0101 0110 ; 2nd word of instruction 0010 0100 0000 0000 addwf reg3 ; continue code
? 2004 microchip technology inc. preliminary ds39625b-page 67 pic18f2585/2680/4585/4680 5.3 data memory organization the data memory in pic18 devices is implemented as static ram. each register in the data memory has a 12-bit address, allowing up to 4096 bytes of data memory. the memory space is divided into as many as 16 banks that contain 256 bytes each; pic18f2585/2680/4585/4680 devices implement all 16 banks. figure 5-5 shows the data memory organization for the pic18f2585/2680/4585/4680 devices. the data memory contains special function registers (sfrs) and general purpose registers (gprs). the sfrs are used for control and status of the controller and peripheral functions, while gprs are used for data storage and scratchpad operations in the user?s application. any read of an unimplemented location will read as ? 0 ?s. the instruction set and architecture allow operations across all banks. the entire data memory may be accessed by direct, indirect or indexed addressing modes. addressing modes are discussed later in this subsection. to ensure that commonly used registers (sfrs and select gprs) can be accessed in a single cycle, pic18 devices implement an access bank. this is a 256-byte memory space that provides fast access to sfrs and the lower portion of gpr bank 0 without using the bsr. section 5.3.2 ?access bank? provides a detailed description of the access ram. 5.3.1 bank select register (bsr) large areas of data memory require an efficient addressing scheme to make rapid access to any address possible. ideally, this means that an entire address does not need to be provided for each read or write operation. for pic18 devices, this is accom- plished with a ram banking scheme. this divides the memory space into 16 contiguous banks of 256 bytes. depending on the instruction, each location can be addressed directly by its full 12-bit address, or an 8-bit low-order address and a 4-bit bank pointer. most instructions in the pic18 instruction set make use of the bank pointer, known as the bank select register (bsr). this sfr holds the 4 most significant bits of a location?s address; the instruction itself includes the 8 least significant bits. only the four lower bits of the bsr are implemented (bsr3:bsr0). the upper four bits are unused; they will always read ? 0 ? and cannot be written to. the bsr can be loaded directly by using the movlb instruction. the value of the bsr indicates the bank in data mem- ory; the 8 bits in the instruction show the location in the bank and can be thought of as an offset from the bank?s lower boundary. the relationship between the bsr?s value and the bank division in data memory is shown in figure 5-6. since up to 16 registers may share the same low-order address, the user must always be careful to ensure that the proper bank is selected before performing a data read or write. for example, writing what should be program data to an 8-bit address of f9h while the bsr is 0fh, will end up resetting the program counter. while any bank can be selected, only those banks that are actually implemented can be read or written to. writes to unimplemented banks are ignored, while reads from unimplemented banks will return ? 0 ?s. even so, the status register will still be affected as if the operation was successful. the data memory map in figure 5-5 indicates which banks are implemented. in the core pic18 instruction set, only the movff instruction fully specifies the 12-bit address of the source and target registers. this instruction ignores the bsr completely when it executes. all other instructions include only the low-order address as an operand and must use either the bsr or the access bank to locate their target registers. note: the operation of some aspects of data memory are changed when the pic18 extended instruction set is enabled. see section 5.6 ?data memory and the extended instruction set? for more information.
pic18f2585/2680/4585/4680 ds39625b-page 68 preliminary ? 2004 microchip technology inc. figure 5-5: data memory map for pic18f2585/2680/4585/4680 devices bank 0 bank 1 bank 14 bank 15 data memory map bsr<3:0> = 0000 = 0001 = 1111 060h 05fh f60h fffh 00h 5fh 60h ffh access bank when a = 0 : the bsr is ignored and the access bank is used. the first 128 bytes are general purpose ram (from bank 0). the second 128 bytes are special function registers (from bank 15). when a = 1 : the bsr specifies the bank used by the instruction. f5fh f00h effh 1ffh 100h 0ffh 000h access ram ffh 00h ffh 00h ffh 00h gpr gpr sfr can sfrs access ram high access ram low bank 2 = 0110 = 0010 (sfrs) 2ffh 200h 3ffh 300h 4ffh 400h 5ffh 500h 6ffh 600h 7ffh 700h 8ffh 800h 9ffh 900h affh a00h bffh b00h cffh c00h dffh d00h e00h bank 3 bank 4 bank 5 bank 6 bank 7 bank 8 bank 9 bank 10 bank 11 bank 12 bank 13 ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h gpr gpr gpr gpr gpr gpr gpr gpr gpr gpr gpr can sfrs can sfrs ffh 00h = 0011 = 0100 = 0101 = 0111 = 1000 = 1001 = 1010 = 1011 = 1100 = 1101 = 1110
? 2004 microchip technology inc. preliminary ds39625b-page 69 pic18f2585/2680/4585/4680 figure 5-6: use of the bank select register (direct addressing) 5.3.2 access bank while the use of the bsr with an embedded 8-bit address allows users to address the entire range of data memory, it also means that the user must always ensure that the correct bank is selected. otherwise, data may be read from or written to the wrong location. this can be disastrous if a gpr is the intended target of an operation, but an sfr is written to instead. verifying and/or changing the bsr for each read or write to data memory can become very inefficient. to streamline access for the most commonly used data memory locations, the data memory is configured with an access bank, which allows users to access a mapped block of memory without specifying a bsr. the access bank consists of the first 128 bytes of memory (00h-7fh) in bank 0 and the last 128 bytes of memory (80h-ffh) in block 15. the lower half is known as the ?access ram? and is composed of gprs. the upper half is also where the device?s sfrs are mapped. these two areas are mapped contiguously in the access bank and can be addressed in a linear fashion by an 8-bit address (figure 5-5). the access bank is used by core pic18 instructions that include the access ram bit (the ?a? parameter in the instruction). when ?a? is equal to ? 1 ?, the instruction uses the bsr and the 8-bit address included in the opcode for the data memory address. when ?a? is ? 0 ? however, the instruction is forced to use the access bank address map; the current value of the bsr is ignored entirely. using this ?forced? addressing allows the instruction to operate on a data address in a single cycle, without updating the bsr first. for 8-bit addresses of 80h and above, this means that users can evaluate and operate on sfrs more efficiently. the access ram below 80h is a good place for data values that the user might need to access rapidly, such as immediate computational results or common program variables. access ram also allows for faster and more code efficient context saving and switching of variables. the mapping of the access bank is slightly different when the extended instruction set is enabled (xinst configuration bit = 1 ). this is discussed in more detail in section 5.6.3 ?mapping the access bank in indexed literal offset mode? . 5.3.3 general purpose register file pic18 devices may have banked memory in the gpr area. this is data ram, which is available for use by all instructions. gprs start at the bottom of bank 0 (address 000h) and grow upwards towards the bottom of the sfr area. gprs are not initialized by a power-on reset and are unchanged on all other resets. note 1: the access ram bit of the instruction can be used to force an override of the selected bank (bsr<3:0>) to the registers of the access bank. 2: the movff instruction embeds the entire 12-bit address in the instruction. data memory bank select (2) 7 0 from opcode (2) 0000 000h 100h 200h 300h f00h e00h fffh bank 0 bank 1 bank 2 bank 14 bank 15 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh bank 3 through bank 13 0011 11111111 7 0 bsr (1)
pic18f2585/2680/4585/4680 ds39625b-page 70 preliminary ? 2004 microchip technology inc. 5.3.4 special function registers the special function registers (sfrs) are registers used by the cpu and peripheral modules for controlling the desired operation of the device. these registers are implemented as static ram. sfrs start at the top of data memory (fffh) and extend downward to occupy the top half of bank 15 (f80h to fffh). a list of these registers is given in table 5-1 and table 5-2. the sfrs can be classified into two sets: those associated with the ?core? device functionality (alu, resets and interrupts) and those related to the peripheral functions. the reset and interrupt registers are described in their respective chapters, while the alu?s status register is described later in this section. registers related to the operation of a peripheral feature are described in the chapter for that peripheral. the sfrs are typically distributed among the peripherals whose functions they control. unused sfr locations are unimplemented and read as ? 0 ?s. table 5-1: special function register map for pic18f2585/2680/4585/4680 devices address name address name address name address name fffh tosu fdfh indf2 (4) fbfh ccpr1h f9fh ipr1 ffeh tosh fdeh postinc2 (4) fbeh ccpr1l f9eh pir1 ffdh tosl fddh postdec2 (4) fbdh ccp1con f9dh pie1 ffch stkptr fdch preinc2 (4) fbch eccpr1h (2) f9ch ? ffbh pclatu fdbh plusw2 (4) fbbh eccpr1l (2) f9bh osctune ffah pclath fdah fsr2h fbah eccp1con (2) f9ah ? ff9h pcl fd9h fsr2l fb9h ? f99h ? ff8h tblptru fd8h status fb8h baudcon f98h ? ff7h tblptrh fd7h tmr0h fb7h eccp1del f97h ? ff6h tblptrl fd6h tmr0l fb6h eccp1as (2) f96h trise (2) ff5h tablat fd5h t0con fb5h cvrcon (2) f95h trisd (2) ff4h prodh fd4h ?fb4hcmcon (1) f94h trisc ff3h prodl fd3h osccon fb3h tmr3h f93h trisb ff2h intcon fd2h hlvdcon fb2h tmr3l f92h trisa ff1h intcon2 fd1h wdtcon fb1h t3con f91h ? ff0h intcon3 fd0h rcon fb0h spbrgh f90h ? fefh indf0 (4) fcfh tmr1h fafh spbrg f8fh ? feeh postinc0 (4) fceh tmr1l faeh rcreg f8eh ? fedh postdec0 (4) fcdh t1con fadh txreg f8dh late (2) fech preinc0 (4) fcch tmr2 fach txsta f8ch latd (2) febh plusw0 (4) fcbh pr2 fabh rcsta f8bh latc feah fsr0h fcah t2con faah eeadrh f8ah latb fe9h fsr0l fc9h sspbuf fa9h eeadr f89h lata fe8h wreg fc8h sspadd fa8h eedata f88h ? fe7h indf1 (4) fc7h sspstat fa7h eecon2 (4) f87h ? fe6h postinc1 (4) fc6h sspcon1 fa6h eecon1 f86h ? fe5h postdec1 (4) fc5h sspcon2 fa5h ipr3 f85h ? fe4h preinc1 (4) fc4h adresh fa4h pir3 f84h porte fe3h plusw1 (4) fc3h adresl fa3h pie3 f83h portd (2) fe2h fsr1h fc2h adcon0 fa2h ipr2 f82h portc fe1h fsr1l fc1h adcon1 fa1h pir2 f81h portb fe0h bsr fc0h adcon2 fa0h pie2 f80h porta note 1: re3 bit only available when mclre = 0 ; otherwise, the bit reads as ? 0 ?. 2: bits and registers available only when enports = 1 ; otherwise, the registers/bits read as ? 0 ?. 3: when any tx_enn bit in rx_tx_seln is set, then the co rresponding bit in this register has transmit properties. 4: this is not a physical register.
? 2004 microchip technology inc. preliminary ds39625b-page 71 pic18f2585/2680/4585/4680 address name address name address name address name f7fh ? f5fh cancon f3fh cancon f1fh rxm1eidl f7eh ? f5eh canstat f3eh canstat f1eh rxm1eidh f7dh ? f5dh rxb1d7 f3dh txb1d7 f1dh rxm1sidl f7ch ? f5ch rxb1d6 f3ch txb1d6 f1ch rxm1sidh f7bh ? f5bh rxb1d5 f3bh txb1d5 f1bh rxm0eidl f7ah ? f5ah rxb1d4 f3ah txb1d4 f1ah rxm0eidh f79h ? f59h rxb1d3 f39h txb1d3 f19h rxm0sidl f78h ? f58h rxb1d2 f38h txb1d2 f18h rxm0sidh f77h ecancon f57h rxb1d1 f37h txb1d1 f17h rxf5eidl f76h txerrcnt f56h rxb1d0 f36h txb1d0 f16h rxf5eidh f75h rxerrcnt f55h rxb1dlc f35h txb1dlc f15h rxf5sidl f74h comstat f54h rxb1eidl f34h txb1eidl f14h rxf5sidh f73h ciocon f53h rxb1eidh f33h txb1eidh f13h rxf4eidl f72h brgcon3 f52h rxb1sidl f32h txb1sidl f12h rxf4eidh f71h brgcon2 f51h rxb1sidh f31h txb1sidh f11h rxf4sidl f70h brgcon1 f50h rxb1con f30h txb1con f10h rxf4sidh f6fh cancon f4fh cancon f2fh cancon f0fh rxf3eidl f6eh canstat f4eh canstat f2eh canstat f0eh rxf3eidh f6dh rxb0d7 f4dh txb0d7 f2dh txb2d7 f0dh rxf3sidl f6ch rxb0d6 f4ch txb0d6 f2ch txb2d6 f0ch rxf3sidh f6bh rxb0d5 f4bh txb0d5 f2bh txb2d5 f0bh rxf2eidl f6ah rxb0d4 f4ah txb0d4 f2ah txb2d4 f0ah rxf2eidh f69h rxb0d3 f49h txb0d3 f29h txb2d3 f09h rxf2sidl f68h rxb0d2 f48h txb0d2 f28h txb2d2 f08h rxf2sidh f67h rxb0d1 f47h txb0d1 f27h txb2d1 f07h rxf1eidl f66h rxb0d0 f46h txb0d0 f26h txb2d0 f06h rxf1eidh f65h rxb0dlc f45h txb0dlc f25h txb2dlc f05h rxf1sidl f64h rxb0eidl f44h txb0eidl f24h txb2eidl f04h rxf1sidh f63h rxb0eidh f43h txb0eidh f23h txb2eidh f03h rxf0eidl f62h rxb0sidl f42h txb0sidl f22h txb2sidl f02h rxf0eidh f61h rxb0sidh f41h txb0sidh f21h txb2sidh f01h rxf0sidl f60h rxb0con f40h txb0con f20h txb2con f00h rxf0sidh table 5-1: special function register map for pic18f2585/2680/4585/4680 devices (continued) note 1: re3 bit only available when mclre = 0 ; otherwise, the bit reads as ? 0 ?. 2: bits and registers available only when enports = 1 ; otherwise, the registers/bits read as ? 0 ?. 3: when any tx_enn bit in rx_tx_seln is set, then the co rresponding bit in this register has transmit properties. 4: this is not a physical register.
pic18f2585/2680/4585/4680 ds39625b-page 72 preliminary ? 2004 microchip technology inc. address name address name address name address name effh ?edfh ?ebfh ?e9fh ? efeh ?edeh ?ebeh ?e9eh ? efdh ?eddh ?ebdh ?e9dh ? efch ?edch ?ebch ?e9ch ? efbh ?edbh ?ebbh ?e9bh ? efah ?edah ?ebah ?e9ah ? ef9h ?ed9h ?eb9h ? e99h ? ef8h ?ed8h ?eb8h ? e98h ? ef7h ?ed7h ?eb7h ? e97h ? ef6h ?ed6h ?eb6h ? e96h ? ef5h ?ed5h ?eb5h ? e95h ? ef4h ?ed4h ?eb4h ? e94h ? ef3h ?ed3h ?eb3h ? e93h ? ef2h ?ed2h ?eb2h ? e92h ? ef1h ?ed1h ?eb1h ? e91h ? ef0h ?ed0h ?eb0h ? e90h ? eefh ?ecfh ?eafh ?e8fh ? eeeh ?eceh ?eaeh ?e8eh ? eedh ?ecdh ?eadh ?e8dh ? eech ?ecch ?each ?e8ch ? eebh ?ecbh ?eabh ?e8bh ? eeah ?ecah ?eaah ?e8ah ? ee9h ?ec9h ?ea9h ? e89h ? ee8h ?ec8h ?ea8h ? e88h ? ee7h ?ec7h ?ea7h ? e87h ? ee6h ?ec6h ?ea6h ? e86h ? ee5h ?ec5h ?ea5h ? e85h ? ee4h ?ec4h ?ea4h ? e84h ? ee3h ?ec3h ?ea3h ? e83h ? ee2h ?ec2h ?ea2h ? e82h ? ee1h ?ec1h ?ea1h ? e81h ? ee0h ?ec0h ?ea0h ? e80h ? table 5-1: special function register map for pic18f2585/2680/4585/4680 devices (continued) note 1: re3 bit only available when mclre = 0 ; otherwise, the bit reads as ? 0 ?. 2: bits and registers available only when enports = 1 ; otherwise, the registers/bits read as ? 0 ?. 3: when any tx_enn bit in rx_tx_seln is set, then the co rresponding bit in this register has transmit properties. 4: this is not a physical register.
? 2004 microchip technology inc. preliminary ds39625b-page 73 pic18f2585/2680/4585/4680 address name address name address name address name e7fh cancon e6fh cancon e5fh cancon e4fh cancon e7eh canstat e6eh canstat e5eh canstat e4eh canstat e7dh b5d7 (3) e6dh b4d7 (3) e5dh b3d7 (3) e4dh b2d7 (3) e7ch b5d6 (3) e6ch b4d6 (3) e5ch b3d6 (3) e4ch b2d6 (3) e7bh b5d5 (3) e6bh b4d5 (3) e5bh b3d5 (3) e4bh b2d5 (3) e7ah b5d4 (3) e6ah b4d4 (3) e5ah b3d4 (3) e4ah b2d4 (3) e79h b5d3 (3) e69h b4d3 (3) e59h b3d3 (3) e49h b2d3 (3) e78h b5d2 (3) e68h b4d2 (3) e58h b3d2 (3) e48h b2d2 (3) e77h b5d1 (3) e67h b4d1 (3) e57h b3d1 (3) e47h b2d1 (3) e76h b5d0 (3) e66h b4d0 (3) e56h b3d0 (3) e46h b2d0 (3) e75h b5dlc (3) e65h b4dlc (3) e55h b3dlc (3) e45h b2dlc (3) e74h b5eidl (3) e64h b4eidl (3) e54h b3eidl (3) e44h b2eidl (3) e73h b5eidh (3) e63h b4eidh (3) e53h b3eidh (3) e43h b2eidh (3) e72h b5sidl (3) e62h b4sidl (3) e52h b3sidl (3) e42h b2sidl (3) e71h b5sidh (3) e61h b4sidh (3) e51h b3sidh (3) e41h b2sidh (3) e70h b5con (3) e60h b4con (3) e50h b3con (3) e40h b2con (3) e3fh cancon e2fh cancon e1fh ?e0fh ? e3eh canstat e2eh canstat e1eh ?e0eh ? e3dh b1d7 (3) e2dh b0d7 (3) e1dh ?e0dh ? e3ch b1d6 (3) e2ch b0d6 (3) e1ch ?e0ch ? e3bh b1d5 (3) e2bh b0d5 (3) e1bh ?e0bh ? e3ah b1d4 (3) e2ah b0d4 (3) e1ah ?e0ah ? e39h b1d3 (3) e29h b0d3 (3) e19h ? e09h ? e38h b1d2 (3) e28h b0d2 (3) e18h ? e08h ? e37h b1d1 (3) e27h b0d1 (3) e17h ? e07h ? e36h b1d0 (3) e26h b0d0 (3) e16h ? e06h ? e35h b1dlc (3) e25h b0dlc (3) e15h ? e05h ? e34h b1eidl (3) e24h b0eidl (3) e14h ? e04h ? e33h b1eidh (3) e23h b0eidh (3) e13h ? e03h ? e32h b1sidl (3) e22h b0sidl (3) e12h ? e02h ? e31h b1sidh (3) e21h b0sidh (3) e11h ? e01h ? e30h b1con (3) e20h b0con (3) e10h ? e00h ? table 5-1: special function register map for pic18f2585/2680/4585/4680 devices (continued) note 1: re3 bit only available when mclre = 0 ; otherwise, the bit reads as ? 0 ?. 2: bits and registers available only when enports = 1 ; otherwise, the registers/bits read as ? 0 ?. 3: when any tx_enn bit in rx_tx_seln is set, then the co rresponding bit in this register has transmit properties. 4: this is not a physical register.
pic18f2585/2680/4585/4680 ds39625b-page 74 preliminary ? 2004 microchip technology inc. address name address name address name address name dffh ? ddfh ?dbfh ?d9fh ? dfeh ? ddeh ?dbeh ?d9eh ? dfdh ?dddh ?dbdh ?d9dh ? dfch txbie ddch ?dbch ?d9ch ? dfbh ? ddbh ?dbbh ?d9bh ? dfah bie0 ddah ?dbah ?d9ah ? df9h ?dd9h ?db9h ? d99h ? df8h bsel0 dd8h sdflc db8h ? d98h ? df7h ?dd7h ?db7h ? d97h ? df6h ?dd6h ?db6h ? d96h ? df5h ? dd5h rxfcon1 db5h ? d95h ? df4h ? dd4h rxfcon0 db4h ? d94h ? df3h msel3 dd3h ?db3h ? d93h rxf15eidl df2h msel2 dd2h ?db2h ? d92h rxf15eidh df1h msel1 dd1h ?db1h ? d91h rxf15sidl df0h msel0 dd0h ?db0h ? d90h rxf15sidh defh ? dcfh ?dafh ?d8fh ? deeh ? dceh ?daeh ?d8eh ? dedh ?dcdh ?dadh ?d8dh ? dech ?dcch ?dach ?d8ch ? debh ? dcbh ?dabh ?d8bhrxf14eidl deah ? dcah ?daah ? d8ah rxf14eidh de9h ?dc9h ?da9h ? d89h rxf14sidl de8h ?dc8h ?da8h ? d88h rxf14sidh de7h rxfbcon7 dc7h ?da7h ? d87h rxf13eidl de6h rxfbcon6 dc6h ?da6h ? d86h rxf13eidh de5h rxfbcon5 dc5h ?da5h ? d85h rxf13sidl de4h rxfbcon4 dc4h ?da4h ? d84h rxf13sidh de3h rxfbcon3 dc3h ?da3h ? d83h rxf12eidl de2h rxfbcon2 dc2h ?da2h ? d82h rxf12eidh de1h rxfbcon1 dc1h ?da1h ? d81h rxf12sidl de0h rxfbcon0 dc0h ?da0h ? d80h rxf12sidh table 5-1: special function register map for pic18f2585/2680/4585/4680 devices (continued) note 1: re3 bit only available when mclre = 0 ; otherwise, the bit reads as ? 0 ?. 2: bits and registers available only when enports = 1 ; otherwise, the registers/bits read as ? 0 ?. 3: when any tx_enn bit in rx_tx_seln is set, then the co rresponding bit in this register has transmit properties. 4: this is not a physical register.
? 2004 microchip technology inc. preliminary ds39625b-page 75 pic18f2585/2680/4585/4680 address name d7fh ? d7eh ? d7dh ? d7ch ? d7bh rxf11eidl d7ah rxf11eidh d79h rxf11sidl d78h rxf11sidh d77h rxf10eidl d76h rxf10eidh d75h rxf10sidl d74h rxf10sidh d73h rxf9eidl d72h rxf9eidh d71h rxf9sidl d70h rxf9sidh d6fh ? d6eh ? d6dh ? d6ch ? d6bh rxf8eidl d6ah rxf8eidh d69h rxf8sidl d68h rxf8sidh d67h rxf7eidl d66h rxf7eidh d65h rxf7sidl d64h rxf7sidh d63h rxf6eidl d62h rxf6eidh d61h rxf6sidl d60h rxf6sidh table 5-1: special function register map for pic18f2585/2680/4585/4680 devices (continued) note 1: re3 bit only available when mclre = 0 ; otherwise, the bit reads as ? 0 ?. 2: bits and registers available only when enports = 1 ; otherwise, the registers/bits read as ? 0 ?. 3: when any tx_enn bit in rx_tx_seln is set, then the co rresponding bit in this register has transmit properties. 4: this is not a physical register.
pic18f2585/2680/4585/4680 ds39625b-page 76 preliminary ? 2004 microchip technology inc. table 5-2: register file summary (pic18f2585/2680/4585/4680) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: tosu ? ? ? top-of-stack upper byte (tos<20:16>) ---0 0000 49, 62 tosh top-of-stack high byte (tos<15:8>) 0000 0000 49, 62 tosl top-of-stack low byte (tos<7:0>) 0000 0000 49, 62 stkptr stkful stkunf ? return stack pointer 00-0 0000 49, 63 pclatu ? ?bit 21 (1) holding register for pc<20:16> ---0 0000 49, 62 pclath holding register for pc<15:8> 0000 0000 49, 62 pcl pc low byte (pc<7:0>) 0000 0000 49, 62 tblptru ? ? bit 21 program memory table pointer upper byte (tblptr<20:16>) --00 0000 49, 103 tblptrh program memory table pointer high byte (tblptr<15:8>) 0000 0000 49, 103 tblptrl program memory table pointer low byte (tblptr<7:0>) 0000 0000 49, 103 tablat program memory table latch 0000 0000 49, 103 prodh product register high byte xxxx xxxx 49, 111 prodl product register low byte xxxx xxxx 49, 111 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 49, 115 intcon2 rbpu intedg0 intedg1 intedg2 ?tmr0ip ?rbip 1111 -1-1 49, 116 intcon3 int2ip int1ip ? int2ie int1ie ? int2if int1if 11-0 0-00 49, 117 indf0 uses contents of fsr0 to address data memory ? value of fsr0 not changed (not a physical register) n/a 49, 89 postinc0 uses contents of fsr0 to address data memory ? value of fsr0 post-incremented (not a physical register) n/a 49, 90 postdec0 uses contents of fsr0 to address data memory ? value of fsr0 post-decremented (not a physical register) n/a 49, 90 preinc0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register) n/a 49, 90 plusw0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register), value of fsr0 offset by w n/a 49, 90 fsr0h ? ? ? ? indirect data memory address pointer 0 high ---- xxxx 49, 89 fsr0l indirect data memory address pointer 0 low byte xxxx xxxx 49, 89 wreg working register xxxx xxxx 49 indf1 uses contents of fsr1 to address data memory ? value of fsr1 not changed (not a physical register) n/a 49, 89 postinc1 uses contents of fsr1 to address data memory ? value of fsr1 post-incremented (not a physical register) n/a 49, 90 postdec1 uses contents of fsr1 to address data memory ? value of fsr1 post-decremented (not a physical register) n/a 49, 90 preinc1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register) n/a 49, 90 plusw1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register), value of fsr1 offset by w n/a 49, 90 fsr1h ? ? ? ? indirect data memory address pointer 1 high ---- xxxx 49, 89 fsr1l indirect data memory address pointer 1 low byte xxxx xxxx 49, 89 bsr ? ? ? ? bank select register ---- 0000 50, 67 indf2 uses contents of fsr2 to address data memory ? value of fsr2 not changed (not a physical register) n/a 50, 89 postinc2 uses contents of fsr2 to address data memory ? value of fsr2 post-incremented (not a physical register) n/a 50, 90 postdec2 uses contents of fsr2 to address data memory ? value of fsr2 post-decremented (not a physical register) n/a 50, 90 preinc2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register) n/a 50, 90 plusw2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register), value of fsr2 offset by w n/a 50, 90 fsr2h ? ? ? ? indirect data memory address pointer 2 high ---- xxxx 50, 89 fsr2l indirect data memory address pointer 2 low byte xxxx xxxx 50, 89 legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: bit 21 of the pc is only available in test mode and serial programming modes. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 3: these registers and/or bits are not implemented on pic18f2x8x devices and are read as ? 0 ?. reset values are shown for pic18f4x8x devices; individual unimplemented bits should be interpreted as ???. 4: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 5: the re3 bit is only available when master clear reset is disabled (config3h<7> = 0 ); otherwise, re3 reads as ? 0 ?. this bit is read-only. 6: ra6/ra7 and their associated latch and direction bits are individually configured as port pins based on various primary oscilla tor modes. when disabled, these bits read as ?0?. 7: can bits have multiple functions depending on the selected mode of the can module. 8: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2. 9: these registers are available on pic18f4x8x devices only.
? 2004 microchip technology inc. preliminary ds39625b-page 77 pic18f2585/2680/4585/4680 status ? ? ?nov z dc c ---x xxxx 50, 87 tmr0h timer0 register high byte 0000 0000 50, 149 tmr0l timer0 register low byte xxxx xxxx 50, 149 t0con tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 1111 1111 50, 149 osccon idlen ircf2 ircf1 ircf0 osts iofs scs1 scs0 0000 q000 30, 50 hlvdcon vdirmag ? irvst hlvden hlvdl3 hlvdl2 hlvdl1 hlvdl0 0-00 0101 50, 267 wdtcon ? ? ? ? ? ? ?swdten --- ---0 50, 353 rcon ipen sboren (2) ?ri to pd por bor 0q-1 11q0 50, 127 tmr1h timer1 register high byte xxxx xxxx 50, 155 tmr1l timer1 register low byte 0000 0000 50, 155 t1con rd16 t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 50, 151 tmr2 timer2 register 1111 1111 50, 158 pr2 timer2 period register -000 0000 50, 155 t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 -000 0000 50, 157 sspbuf ssp receive buffer/transmit register xxxx xxxx 50, 195 sspadd ssp address register in i 2 c slave mode. ssp baud rate reload register in i 2 c master mode. 0000 0000 50, 195 sspstat smp cke d/a psr/w ua bf 0000 0000 50, 197 sspcon1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 50, 198 sspcon2 gcen ackstat ackdt acken rcen pen rsen sen 0000 0000 50, 199 adresh a/d result register high byte xxxx xxxx 50, 256 adresl a/d result register low byte xxxx xxxx 50, 256 adcon0 ? ? chs3 chs2 chs1 chs0 go/done adon --00 0000 50, 247 adcon1 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 --00 0qqq 50, 248 adcon2 adfm ? acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 0-00 0000 50, 249 ccpr1h capture/compare/pwm register 1 high byte xxxx xxxx 51, 168 ccpr1l capture/compare/pwm register 1 low byte xxxx xxxx 51, 168 ccp1con ? ? dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 --xx xxxx 51, 163 eccpr1h (9) enhanced capture/compare/pwm register 1 high byte xxxx xxxx 51, 167 eccpr1l (9) enhanced capture/compare/pwm register 1 low byte xxxx xxxx 51, 167 eccp1con (9) epwm1m1 epwm1m0 edc1b1 edc1b0 eccp1m3 eccp1m2 eccp1m1 eccp1m0 0000 0000 51, 168 baudcon abdovf rcidl ? sckp brg16 ? wue abden 01-0 0000 51, 230 eccp1del (9) prsen pdc6 (3) pdc5 (3) pdc4 (3) pdc3 (3) pdc2 (3) pdc1 (3) pdc0 (3) 0000 0000 51, 182 eccp1as (9) eccpase eccpas2 eccpas1 eccpas0 pssac1 pssac0 pssbd1 (3) pssbd0 (3) 0000 0000 51, 183 cvrcon (9) cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 0000 0000 51, 263 cmcon (9) c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 51, 257 tmr3h timer3 register high byte xxxx xxxx 51, 161 tmr3l timer3 register low byte xxxx xxxx 51, 161 t3con rd16 t3eccp1 (9) t3ckps1 t3ckps0 t3ccp1 (9) t3sync tmr3cs tmr3on 0000 0000 51, 161 table 5-2: register file summary (pic18f2585/2680/4585/4680) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: bit 21 of the pc is only available in test mode and serial programming modes. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 3: these registers and/or bits are not implemented on pic18f2x8x devices and are read as ? 0 ?. reset values are shown for pic18f4x8x devices; individual unimplemented bits should be interpreted as ???. 4: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 5: the re3 bit is only available when master clear reset is disabled (config3h<7> = 0 ); otherwise, re3 reads as ? 0 ?. this bit is read-only. 6: ra6/ra7 and their associated latch and direction bits are individually configured as port pins based on various primary oscilla tor modes. when disabled, these bits read as ?0?. 7: can bits have multiple functions depending on the selected mode of the can module. 8: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2. 9: these registers are available on pic18f4x8x devices only.
pic18f2585/2680/4585/4680 ds39625b-page 78 preliminary ? 2004 microchip technology inc. spbrgh eusart baud rate generator high byte 0000 0000 51, 231 spbrg eusart baud rate generator 0000 0000 51, 231 rcreg eusart receive register 0000 0000 51, 238 txreg eusart transmit register 0000 0000 51, 236 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 51, 237 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 51, 237 eeadrh ? ? ? ? ? ? eeprom addr register high ---- --00 51, 108 eeadr eeprom address register 0000 0000 51, 105 eedata eeprom data register 0000 0000 51, 105 eecon2 eeprom control register 2 (not a physical register) 0000 0000 51, 105 eecon1 eepgd cfgs ? free wrerr wren wr rd xx-0 x000 51, 105 ipr3 mode 0 irxip wakip errip txb2ip txb1ip txb0ip rxb1ip rxb0ip 1111 1111 51, 126 ipr3 mode 1, 2 irxip wakip errip txbnip txb1ip (8) txb0ip (8) rxbnip fifowmip 1111 1111 51, 126 pir3 mode 0 irxif wakif errif txb2if txb1if txb0if rxb1if rxb0if 0000 0000 51, 120 pir3 mode 1, 2 irxif wakif errif txbnif txb1if (8) txb0if (8) rxbnif fifowmif 0000 0000 51, 120 pie3 mode 0 irxie wakie errie txb2ie txb1ie txb0ie rxb1ie rxb0ie 0000 0000 51, 123 pie3 mode 1, 2 irxie wakie errie txbnie txb1ie (8) txb0ie (8) rxbnie fifomwie 0000 0000 51, 123 ipr2 oscfip cmip (9) ? eeip bclip hlvdip tmr3ip eccp1ip (9) 11-1 1111 51, 125 pir2 oscfif cmif (9) ? eeif bclif hlvdif tmr3if eccp1if (9) 00-0 0000 51, 119 pie2 oscfie cmie (9) ? eeie bclie hlvdie tmr3ie eccp1ie (9) 00-0 0000 52, 122 ipr1 pspip (3) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 1111 1111 52, 124 pir1 pspif (3) adif rcif txif sspif ccp1if tmr2if tmr1if 0000 0000 52, 118 pie1 pspie (3) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 52, 121 osctune intsrc pllen (4) ? tun4 tun3 tun2 tun1 tun0 0q-0 0000 27, 52 trise (3) ibf obf ibov pspmode ? trise2 trise1 trise0 0000 -111 52, 141 trisd (3) data direction control register for portd 1111 1111 52, 138 trisc data direction control register for portc 1111 1111 52, 135 trisb data direction control register for portb 1111 1111 52, 132 trisa trisa7 (6) trisa6 (6) data direction control register for porta 1111 1111 52, 129 late (3) ? ? ? ? ? late2 late1 late0 ---- -xxx 52, 141 latd (3) read portd data latch, write portd data latch xxxx xxxx 52, 138 latc read portc data latch, write portc data latch xxxx xxxx 52, 135 latb read portb data latch, write portb data latch xxxx xxxx 52, 132 lata lata7 (6) lata6 (6) read porta data latch, write porta data latch xxxx xxxx 52, 129 table 5-2: register file summary (pic18f2585/2680/4585/4680) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: bit 21 of the pc is only available in test mode and serial programming modes. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 3: these registers and/or bits are not implemented on pic18f2x8x devices and are read as ? 0 ?. reset values are shown for pic18f4x8x devices; individual unimplemented bits should be interpreted as ???. 4: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 5: the re3 bit is only available when master clear reset is disabled (config3h<7> = 0 ); otherwise, re3 reads as ? 0 ?. this bit is read-only. 6: ra6/ra7 and their associated latch and direction bits are individually configured as port pins based on various primary oscilla tor modes. when disabled, these bits read as ?0?. 7: can bits have multiple functions depending on the selected mode of the can module. 8: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2. 9: these registers are available on pic18f4x8x devices only.
? 2004 microchip technology inc. preliminary ds39625b-page 79 pic18f2585/2680/4585/4680 porte (3) ? ? ? ?re3 (5) re2 (3) re1 (3) re0 (3) ---- xxxx 52, 145 portd (3) read portd pins, write portd data latch xxxx xxxx 52, 138 portc read portc pins, write portc data latch xxxx xxxx 52, 135 portb read portb pins, write portb data latch xxxx xxxx 52, 132 porta ra7 (6) ra6 (6) read porta pins, write porta data latch xx00 0000 52, 129 ecancon mdsel1 mdsel0 fifowm ewin4 ewin3 ewin2 ewin1 ewin0 0001 000 52, 280 txerrcnt tec7 tec6 tec5 tec4 tec3 tec2 tec1 tec0 0000 0000 52, 285 rxerrcnt rec7 rec6 rec5 re c4 rec3 rec2 rec1 rec0 0000 0000 52, 293 comstat mode 0 rxb0ovfl rxb1ovfl txbo txbp rxbp txwarn rxwarn ewarn 0000 0000 52, 281 comstat mode 1 ? rxbnovfl txbo txbp rxbp txwarn rxwarn ewarn -000 0000 52, 281 comstat mode 2 fifoempty rxbnovfl txbo txbp rxbp txwarn rxwarn ewarn 0000 0000 52, 281 ciocon ? ? endrhi cancap ? ? ? ? --00 ---- 52, 314 brgcon3 wakdis wakfil ? ? ? seg2ph2 seg2ph1 seg2ph0 00-- -000 52, 313 brgcon2 seg2phts sam seg1ph2 seg1ph1 seg1ph0 prseg2 prseg1 prseg0 0000 0000 52, 312 brgcon1 sjw1 sjw0 brp5 brp4 brp3 brp2 brp1 brp0 0000 0000 52, 311 cancon mode 0 reqop2 reqop1 reqop0 abat win2 (7) win1 (7) win0 (7) ? (7) 1000 000- 53, 276 cancon mode 1 reqop2 reqop1 reqop0 abat ? (7) ? (7) ? (7) ? (7) 1000 ---- 53, 276 cancon mode 2 reqop2 reqop1 reqop0 abat fp3 (7) fp2 (7) fp1 (7) fp0 (7) 1000 0000 53, 276 canstat mode 0 opmode2 opmode1 opmode0 ? (7) icode3 (7) icode2 (7) icode1 (7) ? (7) 000- 0000 53, 277 canstat modes 1, 2 opmode2 opmode1 opmode0 eicode4 (7) eicode3 (7) eicode2 (7) eicode1 (7) eicode0 (7) 0000 0000 53, 277 rxb0d7 rxb0d77 rxb0d76 rxb0d75 rxb0d74 rxb0d73 rxb0d72 rxb0d71 rxb0d70 xxxx xxxx 53, 292 rxb0d6 rxb0d67 rxb0d66 rxb0d65 rxb0d64 rxb0d63 rxb0d62 rxb0d61 rxb0d60 xxxx xxxx 53, 292 rxb0d5 rxb0d57 rxb0d56 rxb0d55 rxb0d54 rxb0d53 rxb0d52 rxb0d51 rxb0d50 xxxx xxxx 53, 292 rxb0d4 rxb0d47 rxb0d46 rxb0d45 rxb0d44 rxb0d43 rxb0d42 rxb0d41 rxb0d40 xxxx xxxx 53, 292 rxb0d3 rxb0d37 rxb0d36 rxb0d35 rxb0d34 rxb0d33 rxb0d32 rxb0d31 rxb0d30 xxxx xxxx 53, 292 rxb0d2 rxb0d27 rxb0d26 rxb0d25 rxb0d24 rxb0d23 rxb0d22 rxb0d21 rxb0d20 xxxx xxxx 53, 292 rxb0d1 rxb0d17 rxb0d16 rxb0d15 rxb0d14 rxb0d13 rxb0d12 rxb0d11 rxb0d10 xxxx xxxx 53, 292 rxb0d0 rxb0d07 rxb0d06 rxb0d05 rxb0d04 rxb0d03 rxb0d02 rxb0d01 rxb0d00 xxxx xxxx 53, 292 rxb0dlc ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 53, 292 rxb0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 53, 291 rxb0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 53, 291 rxb0sidl sid2 sid1 sid0 srr exid ?eid17eid16 xxxx x-xx 53, 291 rxb0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 53, 290 rxb0con mode 0 rxful rxm1 rxm0 (7) ? (7) rxrtrro (7) rxbodben (7) jtoff (7) filhit0 (7) 000- 0000 53, 287 rxb0con mode 1, 2 rxful rxm1 rtrro filhit4 filhit3 filhit2 filhit1 filhit0 0000 0000 53, 287 table 5-2: register file summary (pic18f2585/2680/4585/4680) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: bit 21 of the pc is only available in test mode and serial programming modes. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 3: these registers and/or bits are not implemented on pic18f2x8x devices and are read as ? 0 ?. reset values are shown for pic18f4x8x devices; individual unimplemented bits should be interpreted as ???. 4: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 5: the re3 bit is only available when master clear reset is disabled (config3h<7> = 0 ); otherwise, re3 reads as ? 0 ?. this bit is read-only. 6: ra6/ra7 and their associated latch and direction bits are individually configured as port pins based on various primary oscilla tor modes. when disabled, these bits read as ?0?. 7: can bits have multiple functions depending on the selected mode of the can module. 8: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2. 9: these registers are available on pic18f4x8x devices only.
pic18f2585/2680/4585/4680 ds39625b-page 80 preliminary ? 2004 microchip technology inc. rxb1d7 rxb1d77 rxb1d76 rxb1d75 rxb1d74 rxb1d73 rxb1d72 rxb1d71 rxb1d70 xxxx xxxx 53, 292 rxb1d6 rxb1d67 rxb1d66 rxb1d65 rxb1d64 rxb1d63 rxb1d62 rxb1d61 rxb1d60 xxxx xxxx 53, 292 rxb1d5 rxb1d57 rxb1d56 rxb1d55 rxb1d54 rxb1d53 rxb1d52 rxb1d51 rxb1d50 xxxx xxxx 53, 292 rxb1d4 rxb1d47 rxb1d46 rxb1d45 rxb1d44 rxb1d43 rxb1d42 rxb1d41 rxb1d40 xxxx xxxx 53, 292 rxb1d3 rxb1d37 rxb1d36 rxb1d35 rxb1d34 rxb1d33 rxb1d32 rxb1d31 rxb1d30 xxxx xxxx 53, 292 rxb1d2 rxb1d27 rxb1d26 rxb1d25 rxb1d24 rxb1d23 rxb1d22 rxb1d21 rxb1d20 xxxx xxxx 53, 292 rxb1d1 rxb1d17 rxb1d16 rxb1d15 rxb1d14 rxb1d13 rxb1d12 rxb1d11 rxb1d10 xxxx xxxx 53, 292 rxb1d0 rxb1d07 rxb1d06 rxb1d05 rxb1d04 rxb1d03 rxb1d02 rxb1d01 rxb1d00 xxxx xxxx 53, 292 rxb1dlc ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 53, 292 rxb1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 53, 291 rxb1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 53, 291 rxb1sidl sid2 sid1 sid0 srr exid ?eid17eid16 xxxx xxxx 53, 291 rxb1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 53, 290 rxb1con mode 0 rxful rxm1 rxm0 (7) ? (7) rxrtrro (7) filhit2 (7) filhit1 (7) filhit0 (7) 000- 0000 53, 287 rxb1con mode 1, 2 rxful rxm1 rtrro filhit4 filhit3 filhit2 filhit1 filhit0 0000 0000 53, 287 txb0d7 txb0d77 txb0d76 txb0d75 txb0d74 txb0d73 txb0d72 txb0d71 txb0d70 xxxx xxxx 53, 284 txb0d6 txb0d67 txb0d66 txb0d65 txb0d64 txb0d63 txb0d62 txb0d61 txb0d60 xxxx xxxx 53, 284 txb0d5 txb0d57 txb0d56 txb0d55 txb0d54 txb0d53 txb0d52 txb0d51 txb0d50 xxxx xxxx 54, 284 txb0d4 txb0d47 txb0d46 txb0d45 txb0d44 txb0d43 txb0d42 txb0d41 txb0d40 xxxx xxxx 54, 284 txb0d3 txb0d37 txb0d36 txb0d35 txb0d34 txb0d33 txb0d32 txb0d31 txb0d30 xxxx xxxx 54, 284 txb0d2 txb0d27 txb0d26 txb0d25 txb0d24 txb0d23 txb0d22 txb0d21 txb0d20 xxxx xxxx 54, 284 txb0d1 txb0d17 txb0d16 txb0d15 txb0d14 txb0d13 txb0d12 txb0d11 txb0d10 xxxx xxxx 54, 284 txb0d0 txb0d07 txb0d06 txb0d05 txb0d04 txb0d03 txb0d02 txb0d01 txb0d00 xxxx xxxx 54, 284 txb0dlc ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 54, 285 txb0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 54, 284 txb0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 54, 283 txb0sidl sid2 sid1 sid0 ? exide ?eid17eid16 xxx- x-xx 54, 283 txb0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 54, 283 txb0con txbif txabt txlarb txerr txreq ? txpri1 txpri0 0000 0-00 54, 282 txb1d7 txb1d77 txb1d76 txb1d75 txb1d74 txb1d73 txb1d72 txb1d71 txb1d70 xxxx xxxx 54, 284 txb1d6 txb1d67 txb1d66 txb1d65 txb1d64 txb1d63 txb1d62 txb1d61 txb1d60 xxxx xxxx 54, 284 txb1d5 txb1d57 txb1d56 txb1d55 txb1d54 txb1d53 txb1d52 txb1d51 txb1d50 xxxx xxxx 54, 284 txb1d4 txb1d47 txb1d46 txb1d45 txb1d44 txb1d43 txb1d42 txb1d41 txb1d40 xxxx xxxx 54, 284 txb1d3 txb1d37 txb1d36 txb1d35 txb1d34 txb1d33 txb1d32 txb1d31 txb1d30 xxxx xxxx 54, 284 txb1d2 txb1d27 txb1d26 txb1d25 txb1d24 txb1d23 txb1d22 txb1d21 txb1d20 xxxx xxxx 54, 284 txb1d1 txb1d17 txb1d16 txb1d15 txb1d14 txb1d13 txb1d12 txb1d11 txb1d10 xxxx xxxx 54, 284 txb1d0 txb1d07 txb1d06 txb1d05 txb1d04 txb1d03 txb1d02 txb1d01 txb1d00 xxxx xxxx 54, 284 txb1dlc ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 54, 285 txb1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 54, 284 txb1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 54, 283 table 5-2: register file summary (pic18f2585/2680/4585/4680) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: bit 21 of the pc is only available in test mode and serial programming modes. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 3: these registers and/or bits are not implemented on pic18f2x8x devices and are read as ? 0 ?. reset values are shown for pic18f4x8x devices; individual unimplemented bits should be interpreted as ???. 4: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 5: the re3 bit is only available when master clear reset is disabled (config3h<7> = 0 ); otherwise, re3 reads as ? 0 ?. this bit is read-only. 6: ra6/ra7 and their associated latch and direction bits are individually configured as port pins based on various primary oscilla tor modes. when disabled, these bits read as ?0?. 7: can bits have multiple functions depending on the selected mode of the can module. 8: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2. 9: these registers are available on pic18f4x8x devices only.
? 2004 microchip technology inc. preliminary ds39625b-page 81 pic18f2585/2680/4585/4680 txb1sidl sid2 sid1 sid0 ? exide ?eid17eid16 xxx- x-xx 54, 283 txb1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 54, 283 txb1con txbif txabt txlarb txerr txreq ? txpri1 txpri0 0000 0-00 54, 282 txb2d7 txb2d77 txb2d76 txb2d75 txb2d74 txb2d73 txb2d72 txb2d71 txb2d70 xxxx xxxx 54, 284 txb2d6 txb2d67 txb2d66 txb2d65 txb2d64 txb2d63 txb2d62 txb2d61 txb2d60 xxxx xxxx 54, 284 txb2d5 txb2d57 txb2d56 txb2d55 txb2d54 txb2d53 txb2d52 txb2d51 txb2d50 xxxx xxxx 54, 284 txb2d4 txb2d47 txb2d46 txb2d45 txb2d44 txb2d43 txb2d42 txb2d41 txb2d40 xxxx xxxx 54, 284 txb2d3 txb2d37 txb2d36 txb2d35 txb2d34 txb2d33 txb2d32 txb2d31 txb2d30 xxxx xxxx 54, 284 txb2d2 txb2d27 txb2d26 txb2d25 txb2d24 txb2d23 txb2d22 txb2d21 txb2d20 xxxx xxxx 54, 284 txb2d1 txb2d17 txb2d16 txb2d15 txb2d14 txb2d13 txb2d12 txb2d11 txb2d10 xxxx xxxx 55, 284 txb2d0 txb2d07 txb2d06 txb2d05 txb2d04 txb2d03 txb2d02 txb2d01 txb2d00 xxxx xxxx 55, 284 txb2dlc ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 55, 285 txb2eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 55, 284 txb2eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 55, 283 txb2sidl sid2 sid1 sid0 ? exide ?eid17eid16 xxxx x-xx 55, 283 txb2sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxx- x-xx 55, 283 txb2con txbif txabt txlarb txerr txreq ? txpri1 txpri0 0000 0-00 55, 282 rxm1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 55, 304 rxm1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 55, 304 rxm1sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 55, 304 rxm1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 55, 304 rxm0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 55, 304 rxm0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 55, 304 rxm0sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 55, 304 rxm0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 55, 303 rxf5eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 55, 303 rxf5eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 55, 303 rxf5sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 55, 302 rxf5sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 55, 302 rxf4eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 55, 303 rxf4eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 55, 303 rxf4sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 55, 302 rxf4sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 55, 302 rxf3eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 55, 303 rxf3eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 55, 303 rxf3sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 55, 302 rxf3sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 55, 302 rxf2eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 55, 303 rxf2eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 55, 303 rxf2sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 55, 302 rxf2sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 55, 302 table 5-2: register file summary (pic18f2585/2680/4585/4680) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: bit 21 of the pc is only available in test mode and serial programming modes. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 3: these registers and/or bits are not implemented on pic18f2x8x devices and are read as ? 0 ?. reset values are shown for pic18f4x8x devices; individual unimplemented bits should be interpreted as ???. 4: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 5: the re3 bit is only available when master clear reset is disabled (config3h<7> = 0 ); otherwise, re3 reads as ? 0 ?. this bit is read-only. 6: ra6/ra7 and their associated latch and direction bits are individually configured as port pins based on various primary oscilla tor modes. when disabled, these bits read as ?0?. 7: can bits have multiple functions depending on the selected mode of the can module. 8: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2. 9: these registers are available on pic18f4x8x devices only.
pic18f2585/2680/4585/4680 ds39625b-page 82 preliminary ? 2004 microchip technology inc. rxf1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 56, 303 rxf1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 56, 303 rxf1sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 56, 302 rxf1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 56, 302 rxf0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 56, 303 rxf0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 56, 303 rxf0sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 56, 302 rxf0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 56, 302 b5d7 (8) b5d77 b5d76 b5d75 b5d74 b5d73 b5d72 b5d71 b5d70 xxxx xxxx 56, 299 b5d6 (8) b5d67 b5d66 b5d65 b5d64 b5d63 b5d62 b5d61 b5d60 xxxx xxxx 56, 299 b5d5 (8) b5d57 b5d56 b5d55 b5d54 b5d53 b5d52 b5d51 b5d50 xxxx xxxx 56, 299 b5d4 (8) b5d47 b5d46 b5d45 b5d44 b5d43 b5d42 b5d41 b5d40 xxxx xxxx 56, 299 b5d3 (8) b5d37 b5d36 b5d35 b5d34 b5d33 b5d32 b5d31 b5d30 xxxx xxxx 56, 299 b5d2 (8) b5d27 b5d26 b5d25 b5d24 b5d23 b5d22 b5d21 b5d20 xxxx xxxx 56, 299 b5d1 (8) b5d17 b5d16 b5d15 b5d14 b5d13 b5d12 b5d11 b5d10 xxxx xxxx 56, 299 b5d0 (8) b5d07 b5d06 b5d05 b5d04 b5d03 b5d02 b5d01 b5d00 xxxx xxxx 56, 299 b5dlc (8) receive mode ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 56, 300 b5dlc (8) transmit mode ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 56, 301 b5eidl (8) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 56, 299 b5eidh (8) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 56, 298 b5sidl (8) receive mode sid2 sid1 sid0 srr exid ?eid17eid16 xxxx x-xx 56, 297 b5sidl (8) transmit mode sid2 sid1 sid0 ? exide ?eid17eid16 xxx- x-xx 56, 297 b5sidh (8) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx x-xx 56, 296 b5con (8) receive mode rxful rxm1 rxrtrro filhit4 filhit3 filhit2 filhit1 filhit0 0000 0000 56, 294 b5con (8) transmit mode txbif txabt txlarb txerr txreq rtren txpri1 txpri0 0000 0000 56, 295 b4d7 (8) b4d77 b4d76 b4d75 b4d74 b4d73 b4d72 b4d71 b4d70 xxxx xxxx 56, 299 b4d6 (8) b4d67 b4d66 b4d65 b4d64 b4d63 b4d62 b4d61 b4d60 xxxx xxxx 56, 299 b4d5 (8) b4d57 b4d56 b4d55 b4d54 b4d53 b4d52 b4d51 b4d50 xxxx xxxx 56, 299 b4d4 (8) b4d47 b4d46 b4d45 b4d44 b4d43 b4d42 b4d41 b4d40 xxxx xxxx 56, 299 b4d3 (8) b4d37 b4d36 b4d35 b4d34 b4d33 b4d32 b4d31 b4d30 xxxx xxxx 56, 299 b4d2 (8) b4d27 b4d26 b4d25 b4d24 b4d23 b4d22 b4d21 b4d20 xxxx xxxx 56, 299 b4d1 (8) b4d17 b4d16 b4d15 b4d14 b4d13 b4d12 b4d11 b4d10 xxxx xxxx 56, 299 b4d0 (8) b4d07 b4d06 b4d05 b4d04 b4d03 b4d02 b4d01 b4d00 xxxx xxxx 56, 299 b4dlc (8) receive mode ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 56, 300 b4dlc (8) transmit mode ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 56, 301 table 5-2: register file summary (pic18f2585/2680/4585/4680) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: bit 21 of the pc is only available in test mode and serial programming modes. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 3: these registers and/or bits are not implemented on pic18f2x8x devices and are read as ? 0 ?. reset values are shown for pic18f4x8x devices; individual unimplemented bits should be interpreted as ???. 4: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 5: the re3 bit is only available when master clear reset is disabled (config3h<7> = 0 ); otherwise, re3 reads as ? 0 ?. this bit is read-only. 6: ra6/ra7 and their associated latch and direction bits are individually configured as port pins based on various primary oscilla tor modes. when disabled, these bits read as ?0?. 7: can bits have multiple functions depending on the selected mode of the can module. 8: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2. 9: these registers are available on pic18f4x8x devices only.
? 2004 microchip technology inc. preliminary ds39625b-page 83 pic18f2585/2680/4585/4680 b4eidl (8) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 56, 299 b4eidh (8) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 57, 298 b4sidl (8) receive mode sid2 sid1 sid0 srr exid ?eid17eid16 xxxx x-xx 56, 297 b4sidl (8) transmit mode sid2 sid1 sid0 ? exide ?eid17eid16 xxx- x-xx 56, 297 b4sidh (8) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 57, 296 b4con (8) receive mode rxful rxm1 rxrtrro filhit4 filhit3 filhit2 filhit1 filhit0 0000 0000 57, 294 b4con (8) transmit mode txbif txabt txlarb txerr txreq rtren txpri1 txpri0 0000 0000 57, 295 b3d7 (8) b3d77 b3d76 b3d75 b3d74 b3d73 b3d72 b3d71 b3d70 xxxx xxxx 57, 299 b3d6 (8) b3d67 b3d66 b3d65 b3d64 b3d63 b3d62 b3d61 b3d60 xxxx xxxx 57, 299 b3d5 (8) b3d57 b3d56 b3d55 b3d54 b3d53 b3d52 b3d51 b3d50 xxxx xxxx 57, 299 b3d4 (8) b3d47 b3d46 b3d45 b3d44 b3d43 b3d42 b3d41 b3d40 xxxx xxxx 57, 299 b3d3 (8) b3d37 b3d36 b3d35 b3d34 b3d33 b3d32 b3d31 b3d30 xxxx xxxx 57, 299 b3d2 (8) b3d27 b3d26 b3d25 b3d24 b3d23 b3d22 b3d21 b3d20 xxxx xxxx 57, 299 b3d1 (8) b3d17 b3d16 b3d15 b3d14 b3d13 b3d12 b3d11 b3d10 xxxx xxxx 57, 299 b3d0 (8) b3d07 b3d06 b3d05 b3d04 b3d03 b3d02 b3d01 b3d00 xxxx xxxx 57, 299 b3dlc (8) receive mode ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 56, 300 b3dlc (8) transmit mode ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 56, 301 b3eidl (8) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 57, 299 b3eidh (8) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 57, 298 b3sidl (8) receive mode sid2 sid1 sid0 srr exid ?eid17eid16 xxxx x-xx 56, 297 b3sidl (8) transmit mode sid2 sid1 sid0 ? exide ?eid17eid16 xxx- x-xx 56, 297 b3sidh (8) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 57, 296 b3con (8) receive mode rxful rxm1 rxrtrro filhit4 filhit3 filhit2 filhit1 filhit0 0000 0000 57, 294 b3con (8) transmit mode txbif txabt txlarb txerr txreq rtren txpri1 txpri0 0000 0000 57, 295 b2d7 (8) b2d77 b2d76 b2d75 b2d74 b2d73 b2d72 b2d71 b2d70 xxxx xxxx 57, 299 b2d6 (8) b2d67 b2d66 b2d65 b2d64 b2d63 b2d62 b2d61 b2d60 xxxx xxxx 57, 299 b2d5 (8) b2d57 b2d56 b2d55 b2d54 b2d53 b2d52 b2d51 b2d50 xxxx xxxx 57, 299 b2d4 (8) b2d47 b2d46 b2d45 b2d44 b2d43 b2d42 b2d41 b2d40 xxxx xxxx 57, 299 b2d3 (8) b2d37 b2d36 b2d35 b2d34 b2d33 b2d32 b2d31 b2d30 xxxx xxxx 57, 299 b2d2 (8) b2d27 b2d26 b2d25 b2d24 b2d23 b2d22 b2d21 b2d20 xxxx xxxx 57, 299 b2d1 (8) b2d17 b2d16 b2d15 b2d14 b2d13 b2d12 b2d11 b2d10 xxxx xxxx 57, 299 b2d0 (8) b2d07 b2d06 b2d05 b2d04 b2d03 b2d02 b2d01 b2d00 xxxx xxxx 57, 299 table 5-2: register file summary (pic18f2585/2680/4585/4680) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: bit 21 of the pc is only available in test mode and serial programming modes. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 3: these registers and/or bits are not implemented on pic18f2x8x devices and are read as ? 0 ?. reset values are shown for pic18f4x8x devices; individual unimplemented bits should be interpreted as ???. 4: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 5: the re3 bit is only available when master clear reset is disabled (config3h<7> = 0 ); otherwise, re3 reads as ? 0 ?. this bit is read-only. 6: ra6/ra7 and their associated latch and direction bits are individually configured as port pins based on various primary oscilla tor modes. when disabled, these bits read as ?0?. 7: can bits have multiple functions depending on the selected mode of the can module. 8: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2. 9: these registers are available on pic18f4x8x devices only.
pic18f2585/2680/4585/4680 ds39625b-page 84 preliminary ? 2004 microchip technology inc. b2dlc (8) receive mode ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 56, 300 b2dlc (8) transmit mode ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 56, 301 b2eidl (8) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 57, 299 b2eidh (8) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 57, 298 b2sidl (8) receive mode sid2 sid1 sid0 srr exid ?eid17eid16 xxxx x-xx 56, 297 b2sidl (8) transmit mode sid2 sid1 sid0 ? exide ?eid17eid16 xxx- x-xx 56, 297 b2sidh (8) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 57, 296 b2con (8) receive mode rxful rxm1 rxrtrro filhit4 filhit3 filhit2 filhit1 filhit0 0000 0000 58, 294 b2con (8) transmit mode txbif rxm1 txlarb txerr txreq rtren txpri1 txpri0 0000 0000 58, 295 b1d7 (8) b1d77 b1d76 b1d75 b1d74 b1d73 b1d72 b1d71 b1d70 xxxx xxxx 58, 299 b1d6 (8) b1d67 b1d66 b1d65 b1d64 b1d63 b1d62 b1d61 b1d60 xxxx xxxx 58, 299 b1d5 (8) b1d57 b1d56 b1d55 b1d54 b1d53 b1d52 b1d51 b1d50 xxxx xxxx 58, 299 b1d4 (8) b1d47 b1d46 b1d45 b1d44 b1d43 b1d42 b1d41 b1d40 xxxx xxxx 58, 299 b1d3 (8) b1d37 b1d36 b1d35 b1d34 b1d33 b1d32 b1d31 b1d30 xxxx xxxx 58, 299 b1d2 (8) b1d27 b1d26 b1d25 b1d24 b1d23 b1d22 b1d21 b1d20 xxxx xxxx 58, 299 b1d1 (8) b1d17 b1d16 b1d15 b1d14 b1d13 b1d12 b1d11 b1d10 xxxx xxxx 58, 299 b1d0 (8) b1d07 b1d06 b1d05 b1d04 b1d03 b1d02 b1d01 b1d00 xxxx xxxx 58, 299 b1dlc (8) receive mode ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 56, 300 b1dlc (8) transmit mode ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 56, 301 b1eidl (8) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 58, 299 b1eidh (8) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 58, 298 b1sidl (8) receive mode sid2 sid1 sid0 srr exid ?eid17eid16 xxxx x-xx 56, 297 b1sidl (8) transmit mode sid2 sid1 sid0 ? exide ?eid17eid16 xxx- x-xx 56, 297 b1sidh (8) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 58, 296 b1con (8) receive mode rxful rxm1 rxrtrro filhit4 filhit3 filhit2 filhit1 filhit0 0000 0000 58, 295 b1con (8) transmit mode txbif txabt txlarb txerr txreq rtren txpri1 txpri0 0000 0000 58, 295 b0d7 (8) b0d77 b0d76 b0d75 b0d74 b0d73 b0d72 b0d71 b0d70 xxxx xxxx 58, 299 b0d6 (8) b0d67 b0d66 b0d65 b0d64 b0d63 b0d62 b0d61 b0d60 xxxx xxxx 58, 299 b0d5 (8) b0d57 b0d56 b0d55 b0d54 b0d53 b0d52 b0d51 b0d50 xxxx xxxx 58, 299 b0d4 (8) b0d47 b0d46 b0d45 b0d44 b0d43 b0d42 b0d41 b0d40 xxxx xxxx 58, 299 b0d3 (8) b0d37 b0d36 b0d35 b0d34 b0d33 b0d32 b0d31 b0d30 xxxx xxxx 58, 299 b0d2 (8) b0d27 b0d26 b0d25 b0d24 b0d23 b0d22 b0d21 b0d20 xxxx xxxx 58, 299 b0d1 (8) b0d17 b0d16 b0d15 b0d14 b0d13 b0d12 b0d11 b0d10 xxxx xxxx 58, 299 b0d0 (8) b0d07 b0d06 b0d05 b0d04 b0d03 b0d02 b0d01 b0d00 xxxx xxxx 58, 299 table 5-2: register file summary (pic18f2585/2680/4585/4680) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: bit 21 of the pc is only available in test mode and serial programming modes. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 3: these registers and/or bits are not implemented on pic18f2x8x devices and are read as ? 0 ?. reset values are shown for pic18f4x8x devices; individual unimplemented bits should be interpreted as ???. 4: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 5: the re3 bit is only available when master clear reset is disabled (config3h<7> = 0 ); otherwise, re3 reads as ? 0 ?. this bit is read-only. 6: ra6/ra7 and their associated latch and direction bits are individually configured as port pins based on various primary oscilla tor modes. when disabled, these bits read as ?0?. 7: can bits have multiple functions depending on the selected mode of the can module. 8: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2. 9: these registers are available on pic18f4x8x devices only.
? 2004 microchip technology inc. preliminary ds39625b-page 85 pic18f2585/2680/4585/4680 b0dlc (8) receive mode ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 -xxx xxxx 56, 300 b0dlc (8) transmit mode ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 -x-- xxxx 56, 301 b0eidl (8) eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 58, 299 b0eidh (8) eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 58, 298 b0sidl (8) receive mode sid2 sid1 sid0 srr exid ?eid17eid16 xxxx x-xx 56, 297 b0sidl (8) transmit mode sid2 sid1 sid0 ? exide ?eid17eid16 xxx- x-xx 56, 297 b0sidh (8) sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 58, 296 b0con (8) receive mode rxful rxm1 rxrtrro filhit4 filhit3 filhit2 filhit1 filhit0 0000 0000 58, 295 b0con (8) transmit mode txbif txabt txlarb txerr txreq rtren txpri1 txpri0 0000 0000 58, 295 txbie ? ? ? txb2ie txb1ie txb0ie ? ? ---0 00-- 58, 318 bie0 b5ie b4ie b3ie b2ie b1ie b0ie rxb1ie rxb0ie 0000 0000 58, 318 bsel0 b5txen b4txen b3txen b2txen b1txen b0txen ? ? 0000 00-- 59, 301 msel3 fil15_1 fil15_0 fil14_1 fil14_0 fil13_1 fil13_0 fil12_1 fil12_0 0000 0000 59, 310 msel2 fil11_1 fil11_0 fil10_1 fil10_0 fil9_1 fil9_0 fil8_1 fil8_0 0000 0000 59, 309 msel1 fil7_1 fil7_0 fil6_1 fil6_0 fil5_1 fil5_0 fil4_1 fil4_0 0000 0101 59, 308 msel0 fil3_1 fil3_0 fil2_1 fil2_0 fil1_1 fil1_0 fil0_1 fil0_0 0101 0000 59, 307 rxfbcon7 f15bp_3 f15bp_2 f15bp_1 f15bp_0 f14bp_3 f14bp_2 f14bp_1 f14bp_0 0000 0000 59, 305 rxfbcon6 f13bp_3 f13bp_2 f13bp_1 f13bp_0 f12bp_3 f12bp_2 f12bp_1 f12bp_0 0000 0000 59, 305 rxfbcon5 f11bp_3 f11bp_2 f11bp_1 f11bp_0 f10bp_3 f10bp_2 f10bp_1 f10bp_0 0000 0000 59, 305 rxfbcon4 f9bp_3 f9bp_2 f9bp_1 f9bp_0 f8bp_3 f8bp_2 f8bp_1 f8bp_0 0000 0000 59, 305 rxfbcon3 f7bp_3 f7bp_2 f7bp_1 f7bp_0 f6bp_3 f6bp_2 f6bp_1 f6bp_0 0000 0000 59, 305 rxfbcon2 f5bp_3 f5bp_2 f5bp_1 f5bp_0 f4bp_3 f4bp_2 f4bp_1 f4bp_0 0001 0001 59, 305 rxfbcon1 f3bp_3 f3bp_2 f3bp_1 f3bp_0 f2bp_3 f2bp_2 f2bp_1 f2bp_0 0001 0001 59, 305 rxfbcon0 f1bp_3 f1bp_2 f1bp_1 f1bp_0 f0bp_3 f0bp_2 f0bp_1 f0bp_0 0000 0000 59, 305 sdflc ? ? ? flc4 flc3 flc2 flc1 flc0 ---0 0000 59, 305 rxfcon1 rxf15en rxf14en rxf13en rxf12en rxf11en rxf10en rxf9en rxf8en 0000 0000 59, 306 rxfcon0 rxf7en rxf6en rxf5en rxf4en rxf3en rxf2en rxf1en rxf0en 0000 0000 59, 305 rxf15eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 59, 303 rxf15eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 59, 303 rxf15sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 59, 304 rxf15sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 59, 303 rxf14eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 59, 303 rxf14eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 59, 303 rxf14sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 59, 304 rxf14sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 59, 303 rxf13eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 59, 303 rxf13eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 59, 303 table 5-2: register file summary (pic18f2585/2680/4585/4680) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: bit 21 of the pc is only available in test mode and serial programming modes. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 3: these registers and/or bits are not implemented on pic18f2x8x devices and are read as ? 0 ?. reset values are shown for pic18f4x8x devices; individual unimplemented bits should be interpreted as ???. 4: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 5: the re3 bit is only available when master clear reset is disabled (config3h<7> = 0 ); otherwise, re3 reads as ? 0 ?. this bit is read-only. 6: ra6/ra7 and their associated latch and direction bits are individually configured as port pins based on various primary oscilla tor modes. when disabled, these bits read as ?0?. 7: can bits have multiple functions depending on the selected mode of the can module. 8: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2. 9: these registers are available on pic18f4x8x devices only.
pic18f2585/2680/4585/4680 ds39625b-page 86 preliminary ? 2004 microchip technology inc. rxf13sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 59, 304 rxf13sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 59, 303 rxf12eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 59, 303 rxf12eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 59, 303 rxf12sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 59, 304 rxf12sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 60, 303 rxf11eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 60, 303 rxf11eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 60, 303 rxf11sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 60, 304 rxf11sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 60, 303 rxf10eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 60, 303 rxf10eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 60, 303 rxf10sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 60, 304 rxf10sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 60, 303 rxf9eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 60, 303 rxf9eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 60, 303 rxf9sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 60, 304 rxf9sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 60, 303 rxf8eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 60, 303 rxf8eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 60, 303 rxf8sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 60, 304 rxf8sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 60, 303 rxf7eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 60, 303 rxf7eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 60, 303 rxf7sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 60, 304 rxf7sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 60, 303 rxf6eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 xxxx xxxx 60, 303 rxf6eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 xxxx xxxx 60, 303 rxf6sidl sid2 sid1 sid0 ? exiden ?eid17eid16 xxx- x-xx 60, 304 rxf6sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 xxxx xxxx 60, 303 table 5-2: register file summary (pic18f2585/2680/4585/4680) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: bit 21 of the pc is only available in test mode and serial programming modes. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 3: these registers and/or bits are not implemented on pic18f2x8x devices and are read as ? 0 ?. reset values are shown for pic18f4x8x devices; individual unimplemented bits should be interpreted as ???. 4: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 5: the re3 bit is only available when master clear reset is disabled (config3h<7> = 0 ); otherwise, re3 reads as ? 0 ?. this bit is read-only. 6: ra6/ra7 and their associated latch and direction bits are individually configured as port pins based on various primary oscilla tor modes. when disabled, these bits read as ?0?. 7: can bits have multiple functions depending on the selected mode of the can module. 8: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2. 9: these registers are available on pic18f4x8x devices only.
? 2004 microchip technology inc. preliminary ds39625b-page 87 pic18f2585/2680/4585/4680 5.3.5 status register the status register, shown in register 5-2, contains the arithmetic status of the alu. as with any other sfr, it can be the operand for any instruction. if the status register is the destination for an instruction that affects the z, dc, c, ov or n bits, the results of the instruction are not written; instead, the status is updated according to the instruction performed. there- fore, the result of an instruction with the status register as its destination may be different than intended. as an example, clrf status will set the z bit and leave the remaining status bits unchanged (? 000u u1uu ?). it is recommended that only bcf , bsf , swapf , movff and movwf instructions are used to alter the status register, because these instructions do not affect the z, c, dc, ov or n bits in the status register. for other instructions that do not affect status bits, see the instruction set summaries in table 25-2 and table 25-3. register 5-2: status register note: the c and dc bits operate as the borrow and digit borrow bits respectively in subtraction. u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ?novzdcc bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4 n: negative bit this bit is used for signed arithmetic (2?s complement). it indicates whether the result was negative (alu msb = 1 ). 1 = result was negative 0 = result was positive bit 3 ov: overflow bit this bit is used for signed arithmetic (2?s complement). it indicates an overflow of the 7-bit magnitude which causes the sign bit (bit 7) to change state. 1 = overflow occurred for signed arithmetic (in this arithmetic operation) 0 = no overflow occurred bit 2 z: zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc: digit carry/borrow bit for addwf, addlw, sublw and subwf instructions: 1 = a carry-out from the 4th low-order bit of the result occurred 0 = no carry-out from the 4th low-order bit of the result note: for borrow, the polarity is reversed. a subtraction is executed by adding the two?s complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either the bit 4 or bit 3 of the source register. bit 0 c: carry/borrow bit for addwf, addlw, sublw and subwf instructions: 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note: for borrow, the polarity is reversed. a subtraction is executed by adding the two?s complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either the high or low-order bit of the source register. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 88 preliminary ? 2004 microchip technology inc. 5.4 data addressing modes while the program memory can be addressed in only one way ? through the program counter ? information in the data memory space can be addressed in several ways. for most instructions, the addressing mode is fixed. other instructions may use up to three modes, depending on which operands are used and whether or not the extended instruction set is enabled. the addressing modes are:  inherent  literal direct indirect an additional addressing mode, indexed literal offset, is available when the extended instruction set is enabled (xinst configuration bit = 1 ). its operation is discussed in greater detail in section 5.6.1 ?indexed addressing with literal offset? . 5.4.1 inherent and literal addressing many pic18 control instructions do not need any argument at all; they either perform an operation that globally affects the device or they operate implicitly on one register. this addressing mode is known as inherent addressing. examples include sleep , reset and daw . other instructions work in a similar way but require an additional explicit argument in the opcode. this is known as literal addressing mode because they require some literal value as an argument. examples include addlw and movlw which, respectively, add or move a literal value to the w register. other examples include call and goto , which include a 20-bit program memory address. 5.4.2 direct addressing direct addressing specifies all or part of the source and/or destination address of the operation within the opcode itself. the options are specified by the arguments accompanying the instruction. in the core pic18 instruction set, bit-oriented and byte-oriented instructions use some version of direct addressing by default. all of these instructions include some 8-bit literal address as their least significant byte. this address specifies either a register address in one of the banks of data ram ( section 5.3.3 ?general purpose register file? ) or a location in the access bank ( section 5.3.2 ?access bank? ) as the data source for the instruction. the access ram bit ?a? determines how the address is interpreted. when ?a? is ? 1 ?, the contents of the bsr ( section 5.3.1 ?bank select register (bsr)? ) are used with the address to determine the complete 12-bit address of the register. when ?a? is ? 0 ?, the address is interpreted as being a register in the access bank. addressing that uses the access ram is sometimes also known as direct forced addressing mode. a few instructions, such as movff , include the entire 12-bit address (either source or destination) in their opcodes. in those cases, the bsr is ignored entirely. the destination of the operation?s results is determined by the destination bit ?d?. when ?d? is ? 1 ?, the results are stored back in the source register, overwriting its origi- nal contents. when ?d? is ? 0 ?, the results are stored in the w register. instructions without the ?d? argument have a destination that is implicit in the instruction; their destination is either the target register being operated on or the w register. 5.4.3 indirect addressing indirect addressing allows the user to access a location in data memory without giving a fixed address in the instruction. this is done by using file select registers (fsrs) as pointers to the locations to be read or written to. since the fsrs are themselves located in ram as special file registers, they can also be directly manip- ulated under program control. this makes fsrs very useful in implementing data structures, such as tables and arrays in data memory. the registers for indirect addressing are also imple- mented with indirect file operands (indfs) that permit automatic manipulation of the pointer value with auto-incrementing, auto-decrementing or offsetting with another value. this allows for efficient code, using loops, such as the example of clearing an entire ram bank in example 5-5. example 5-5: how to clear ram (bank 1) using indirect addressing note: the execution of some instructions in the core pic18 instruction set are changed when the pic18 extended instruction set is enabled. see section 5.6 ?data memory and the extended instruction set? for more information. lfsr fsr0, 100h ; next clrf postinc0 ; clear indf ; register then ; inc pointer btfss fsr0h, 1 ; all done with ; bank1? bra next ; no, clear next continue ; yes, continue
? 2004 microchip technology inc. preliminary ds39625b-page 89 pic18f2585/2680/4585/4680 5.4.3.1 fsr registers and the indf operand at the core of indirect addressing are three sets of registers: fsr0, fsr1 and fsr2. each represents a pair of 8-bit registers, fsrnh and fsrnl. the four upper bits of the fsrnh register are not used, so each fsr pair holds a 12-bit value. this represents a value that can address the entire range of the data memory in a linear fashion. the fsr register pairs, then, serve as pointers to data memory locations. indirect addressing is accomplished with a set of indirect file operands, indf0 through indf2. these can be thought of as ?virtual? registers: they are mapped in the sfr space, but are not physically implemented. reading or writing to a particular indf register actually accesses its corresponding fsr register pair. a read from indf1, for example, reads the data at the address indicated by fsr1h:fsr1l. instructions that use the indf registers as operands actually use the contents of their corresponding fsr as a pointer to the instruction?s target. the indf operand is just a convenient way of using the pointer. because indirect addressing uses a full 12-bit address, data ram banking is not necessary. thus, the current contents of the bsr and the access ram bit have no effect on determining the target address. figure 5-7: indirect addressing fsr1h:fsr1l 0 7 data memory 000h 100h 200h 300h f00h e00h fffh bank 0 bank 1 bank 2 bank 14 bank 15 bank 3 through bank 13 addwf, indf1, 1 0 7 using an instruction with one of the indirect addressing registers as the operand.... ...uses the 12-bit address stored in the fsr pair associated with that register.... ...to determine the data memory location to be used in that operation. in this case, the fsr1 pair contains ecch. this means the contents of location ecch will be added to that of the w register and stored back in ecch. xxxx1110 11001100 bank 14
pic18f2585/2680/4585/4680 ds39625b-page 90 preliminary ? 2004 microchip technology inc. 5.4.3.2 fsr registers and postinc, postdec, preinc and plusw in addition to the indf operand, each fsr register pair also has four additional indirect operands. like indf, these are ?virtual? registers that cannot be indirectly read or written to. accessing these registers actually accesses the associated fsr register pair, but also performs a specific action on its stored value. they are:  postdec: accesses the fsr value, then automatically decrements it by 1 afterwards  postinc: accesses the fsr value, then automatically increments it by 1 afterwards  preinc: increments the fsr value by 1, then uses it in the operation  plusw: adds the signed value of the w register (range of -127 to 128) to that of the fsr and uses the new value in the operation. in this context, accessing an indf register uses the value in the fsr registers without changing them. similarly, accessing a plusw register gives the fsr value offset by that in the w register; neither value is actually changed in the operation. accessing the other virtual registers changes the value of the fsr registers. operations on the fsrs with postdec, postinc and preinc affect the entire register pair; that is, rollovers of the fsrnl register from ffh to 00h carry over to the fsrnh register. on the other hand, results of these operations do not change the value of any flags in the status register (e.g., z, n, ov, etc.). the plusw register can be used to implement a form of indexed addressing in the data memory space. by manipulating the value in the w register, users can reach addresses that are fixed offsets from pointer addresses. in some applications, this can be used to implement some powerful program control structure, such as software stacks, inside of data memory. 5.4.3.3 operations by fsrs on fsrs indirect addressing operations that target other fsrs or virtual registers represent special cases. for exam- ple, using an fsr to point to one of the virtual registers will not result in successful operations. as a specific case, assume that fsr0h:fsr0l contains fe7h, the address of indf1. attempts to read the value of the indf1 using indf0 as an operand will return 00h. attempts to write to indf1 using indf0 as the operand will result in a nop . on the other hand, using the virtual registers to write to an fsr pair may not occur as planned. in these cases, the value will be written to the fsr pair but without any incrementing or decrementing. thus, writing to indf2 or postdec2 will write the same value to the fsr2h:fsr2l. since the fsrs are physical registers mapped in the sfr space, they can be manipulated through all direct operations. users should proceed cautiously when working on these registers, particularly if their code uses indirect addressing. similarly, operations by indirect addressing are gener- ally permitted on all other sfrs. users should exercise the appropriate caution that they do not inadvertently change settings that might affect the operation of the device.
? 2004 microchip technology inc. preliminary ds39625b-page 91 pic18f2585/2680/4585/4680 5.5 program memory and the extended instruction set the operation of program memory is unaffected by the use of the extended instruction set. enabling the extended instruction set adds eight additional two-word commands to the existing pic18 instruction set: addfsr , addulnk , callw , movsf , movss , pushl , subfsr and subulnk. these instructions are executed as described in section 5.2.4 ?two-word instructions? . 5.6 data memory and the extended instruction set enabling the pic18 extended instruction set (xinst configuration bit = 1 ) significantly changes certain aspects of data memory and its addressing. specifi- cally, the use of the access bank for many of the core pic18 instructions is different; this is due to the intro- duction of a new addressing mode for the data memory space. this mode also alters the behavior of indirect addressing using fsr2 and its associated operands. what does not change is just as important. the size of the data memory space is unchanged, as well as its linear addressing. the sfr map remains the same. core pic18 instructions can still operate in both direct and indirect addressing mode; inherent and literal instructions do not change at all. indirect addressing with fsr0 and fsr1 also remains unchanged. 5.6.1 indexed addressing with literal offset enabling the pic18 extended instruction set changes the behavior of indirect addressing using the fsr2 register pair and its associated file operands. under the proper conditions, instructions that use the access bank ? that is, most bit-oriented and byte-oriented ? instructions ? can invoke a form of indexed addressing using an offset specified in the instruction. this special addressing mode is known as indexed addressing with literal offset or indexed literal offset mode. when using the extended instruction set, this addressing mode requires the following:  the use of the access bank is forced (?a? = 0 ); and  the file address argument is less than or equal to 5fh. under these conditions, the file address of the instruc- tion is not interpreted as the lower byte of an address (used with the bsr in direct addressing), or as an 8-bit address in the access bank. instead, the value is interpreted as an offset value to an address pointer, specified by fsr2. the offset and the contents of fsr2 are added to obtain the target address of the operation. 5.6.2 instructions affected by indexed literal offset mode any of the core pic18 instructions that can use direct addressing are potentially affected by the indexed literal offset addressing mode. this includes all byte-oriented and bit-oriented instructions, or almost one-half of the standard pic18 instruction set. instruc- tions that only use inherent or literal addressing modes are unaffected. additionally, byte-oriented and bit-oriented instructions are not affected if they use the access bank (access ram bit is ? 1 ?), or include a file address of 60h or above. instructions meeting these criteria will continue to execute as before. a comparison of the different possi- ble addressing modes when the extended instruction set is enabled in shown in figure 5-8. those who desire to use byte-oriented or bit-oriented instructions in the indexed literal offset mode should note the changes to assembler syntax for this mode. this is described in more detail in section 25.2.1 ?extended instruction syntax? .
pic18f2585/2680/4585/4680 ds39625b-page 92 preliminary ? 2004 microchip technology inc. figure 5-8: comparing addressing options for bit-oriented and byte-oriented instructions (extended instruction set enabled) example instruction: addwf, f, d, a (opcode: 0010 01da ffff ffff ) when a = 0 and f 60h: the instruction executes in direct forced mode. ?f? is interpreted as a location in the access ram between 060h and 0ffh. this is the same as the sfrs, or locations f60h to 0ffh (bank 15) of data memory. locations below 60h are not available in this addressing mode. when a = 0 and f 5fh: the instruction executes in indexed literal offset mode. ?f? is interpreted as an offset to the address value in fsr2. the two are added together to obtain the address of the target register for the instruction. the address can be anywhere in the data memory space. note that in this mode, the correct syntax is now: addwf [k], d where ?k? is the same as ?f?. when a = 1 (all values of f): the instruction executes in direct mode (also known as direct long mode). ?f? is interpreted as a location in one of the 16 banks of the data memory space. the bank is designated by the bank select register (bsr). the address can be in any implemented bank in the data memory space. 000h 060h 100h f00h f60h fffh valid range 00h 60h ffh data memory access ram bank 0 bank 1 through bank 14 bank 15 sfrs 000h 080h 100h f00h f60h fffh data memory bank 0 bank 1 through bank 14 bank 15 sfrs fsr2h fsr2l ffffffff 001001da ffffffff 001001da 000h 080h 100h f00h f60h fffh data memory bank 0 bank 1 through bank 14 bank 15 sfrs for ?f? bsr 00000000 080h
? 2004 microchip technology inc. preliminary ds39625b-page 93 pic18f2585/2680/4585/4680 5.6.3 mapping the access bank in indexed literal offset mode the use of indexed literal offset addressing mode effectively changes how the lower half of access ram (00h to 7fh) is mapped. rather than containing just the contents of the bottom half of bank 0, this mode maps the contents from bank 0 and a user defined ?window? that can be located anywhere in the data memory space. the value of fsr2 establishes the lower bound- ary of the addresses mapped into the window, while the upper boundary is defined by fsr2 plus 95 (5fh). addresses in the access ram above 5fh are mapped as previously described (see section 5.3.2 ?access bank? ). an example of access bank remapping in this addressing mode is shown in figure 5-9. remapping of the access bank applies only to opera- tions using the indexed literal offset mode. operations that use the bsr (access ram bit is ? 1 ?) will continue to use direct addressing as before. any indirect or indexed operation that explicitly uses any of the indirect file operands (including fsr2) will continue to operate as standard indirect addressing. any instruction that uses the access bank, but includes a register address of greater than 05fh, will use direct addressing and the normal access bank map. 5.6.4 bsr in indexed literal offset mode although the access bank is remapped when the extended instruction set is enabled, the operation of the bsr remains unchanged. direct addressing using the bsr to select the data memory bank operates in the same manner as previously described. figure 5-9: remapping the access bank with indexed literal offset addressing data memory 000h 100h 200h f60h f00h fffh bank 1 bank 15 bank 2 through bank 14 sfrs addwf f, d, a fsr2h:fsr2l = 120h locations in the region from the fsr2 pointer (120h) to the pointer plus 05fh (17fh) are mapped to the bottom of the access ram (000h-05fh). special file registers at f60h through fffh are mapped to 60h through ffh, as usual. bank 0 addresses below 5fh are not available in this mode. they can still be addressed by using the bsr. access bank 00h 60h ffh bank 0 sfrs bank 1 ?window? window example situation: 120h 17fh 5fh
pic18f2585/2680/4585/4680 ds39625b-page 94 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 95 pic18f2585/2680/4585/4680 6.0 flash program memory the flash program memory is readable, writable and erasable during normal operation over the entire v dd range. a read from program memory is executed on one byte at a time. a write to program memory is executed on blocks of 64 bytes at a time. program memory is erased in blocks of 64 bytes at a time. a bulk erase operation may not be issued from user code. writing or erasing program memory will cease instruction fetches until the operation is complete. the program memory cannot be accessed during the write or erase, therefore, code cannot execute. an internal programming timer terminates program memory writes and erases. a value written to program memory does not need to be a valid instruction. executing a program memory location that forms an invalid instruction results in a nop . 6.1 table reads and table writes in order to read and write program memory, there are two operations that allow the processor to move bytes between the program memory space and the data ram:  table read ( tblrd )  table write ( tblwt ) the program memory space is 16 bits wide, while the data ram space is 8 bits wide. table reads and table writes move data between these two memory spaces through an 8-bit register (tablat). table read operations retrieve data from program memory and place it into the data ram space. figure 6-1 shows the operation of a table read with program memory and data ram. table write operations store data from the data memory space into holding registers in program memory. the procedure to write the contents of the holding registers into program memory is detailed in section 6.5 ?writing to flash program memory? . figure 6-2 shows the operation of a table write with program memory and data ram. table operations work with byte entities. a table block containing data, rather than program instructions, is not required to be word aligned. therefore, a table block can start and end at any byte address. if a table write is being used to write executable code into program memory, program instructions will need to be word aligned. figure 6-1: table read operation table pointer (1) table latch (8-bit) program memory tblptrh tblptrl tablat tblptru instruction: tblrd * note 1: table pointer register points to a byte in program memory. program memory (tblptr)
pic18f2585/2680/4585/4680 ds39625b-page 96 preliminary ? 2004 microchip technology inc. figure 6-2: table write operation 6.2 control registers several control registers are used in conjunction with the tblrd and tblwt instructions. these include the:  eecon1 register  eecon2 register  tablat register  tblptr registers 6.2.1 eecon1 and eecon2 registers the eecon1 register (register 6-1) is the control register for memory accesses. the eecon2 register is not a physical register; it is used exclusively in the memory write and erase sequences. reading eecon2 will read all ? 0 ?s. the eepgd control bit determines if the access will be a program or data eeprom memory access. when clear, any subsequent operations will operate on the data eeprom memory. when set, any subsequent operations will operate on the program memory. the cfgs control bit determines if the access will be to the configuration/calibration registers or to program memory/data eeprom memory. when set, subsequent operations will operate on configuration registers regardless of eepgd (see section 24.0 ?special features of the cpu? ). when clear, memory selection access is determined by eepgd. the free bit, when set, will allow a program memory erase operation. when free is set, the erase opera- tion is initiated on the next wr command. when free is clear, only writes are enabled. the wren bit, when set, will allow a write operation. on power-up, the wren bit is clear. the wrerr bit is set in hardware when the wren bit is set and cleared when the internal programming timer expires and the write operation is complete. the wr control bit initiates write operations. the bit cannot be cleared, only set, in software; it is cleared in hardware at the completion of the write operation. table pointer (1) table latch (8-bit) tblptrh tblptrl tablat program memory (tblptr) tblptru instruction: tblwt * note 1: table pointer actually points to one of 64 holding registers, the address of which is determined by tblptrl<5:0>. the process for physically writing dat a to the program memory array is discussed in section 6.5 ?writing to flash program memory? . holding registers program memory note: during normal operation, the wrerr is read as ? 1 ?. this can indicate that a write operation was prematurely terminated by a reset, or a write operation was attempted improperly. note: the eeif interrupt flag bit (pir2<4>) is set when the write is complete. it must be cleared in software.
? 2004 microchip technology inc. preliminary ds39625b-page 97 pic18f2585/2680/4585/4680 register 6-1: eecon1: data eeprom control register 1 r/w-x r/w-x u-0 r/w-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd cfgs ? free wrerr wren wr rd bit 7 bit 0 bit 7 eepgd: flash program or data eeprom memory select bit 1 = access flash program memory 0 = access data eeprom memory bit 6 cfgs: flash program/data eeprom or configuration select bit 1 = access configuration registers 0 = access flash program or data eeprom memory bit 5 unimplemented: read as ? 0 ? bit 4 free: flash row erase enable bit 1 = erase the program memory row addressed by tblptr on the next wr command (cleared by completion of erase operation) 0 = perform write only bit 3 wrerr: flash program/data eeprom error flag bit 1 = a write operation is prematurely terminated (any reset during self-timed programming in normal operation or an improper write attempt) 0 = the write operation completed note: when a wrerr occurs, the eepgd and cfgs bits are not cleared. this allows tracing of the error condition. bit 2 wren: flash program/data eeprom write enable bit 1 = allows write cycles to flash program/data eeprom 0 = inhibits write cycles to flash program/data eeprom bit 1 wr: write control bit 1 = initiates a data eeprom erase/write cycle or a program memory erase cycle or write cycle (the operation is self-timed and the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software.) 0 = write cycle to the eeprom is complete bit 0 rd: read control bit 1 = initiates an eeprom read (read takes one cycle. rd is cleared in hardware. the rd bit can only be set (not cleared) in software. rd bit cannot be set when eepgd = 1 or cfgs = 1 .) 0 = does not initiate an eeprom read legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 98 preliminary ? 2004 microchip technology inc. 6.2.2 tablat ? table latch register the table latch (tablat) is an 8-bit register mapped into the sfr space. the table latch register is used to hold 8-bit data during data transfers between program memory and data ram. 6.2.3 tblptr ? table pointer register the table pointer (tblptr) register addresses a byte within the program memory. the tblptr is comprised of three sfr registers: table pointer upper byte, table pointer high byte and table pointer low byte (tblptru:tblptrh:tblptrl). these three regis- ters join to form a 22-bit wide pointer. the low-order 21 bits allow the device to address up to 2 mbytes of program memory space. the 22nd bit allows access to the device id, the user id and the configuration bits. the table pointer, tblptr, is used by the tblrd and tblwt instructions. these instructions can update the tblptr in one of four ways based on the table opera- tion. these operations are shown in table 6-1. these operations on the tblptr only affect the low-order 21 bits. 6.2.4 table pointer boundaries tblptr is used in reads, writes and erases of the flash program memory. when a tblrd is executed, all 22 bits of the tblptr determine which byte is read from program memory into tablat. when a tblwt is executed, the six lsbs of the table pointer register (tblptr<5:0>) determine which of the 64 program memory holding registers is written to. when the timed write to program memory begins (via the wr bit), the 16 msbs of the tblptr (tblptr<21:6>) determine which program memory block of 64 bytes is written to. for more detail, see section 6.5 ?writing to flash program memory? . when an erase of program memory is executed, the 16 msbs of the table pointer register (tblptr<21:6>) point to the 64-byte block that will be erased. the least significant bits (tblptr<5:0>) are ignored. figure 6-3 describes the relevant boundaries of tblptr based on flash program memory operations. table 6-1: table pointer operations with tblrd and tblwt instructions figure 6-3: table pointer boundaries based on operation example operation on table pointer tblrd* tblwt* tblptr is not modified tblrd*+ tblwt*+ tblptr is incremented after the read/write tblrd*- tblwt*- tblptr is decremented after the read/write tblrd+* tblwt+* tblptr is incremented before the read/write 21 16 15 87 0 table erase/write table write table read ? tblptr<21:0> tblptrl tblptrh tblptru tblptr<5:0> tblptr<21:6>
? 2004 microchip technology inc. preliminary ds39625b-page 99 pic18f2585/2680/4585/4680 6.3 reading the flash program memory the tblrd instruction is used to retrieve data from program memory and places it into data ram. table reads from program memory are performed one byte at a time. tblptr points to a byte address in program space. executing tblrd places the byte pointed to into tablat. in addition, tblptr can be modified automatically for the next table read operation. the internal program memory is typically organized by words. the least significant bit of the address selects between the high and low bytes of the word. figure 6-4 shows the interface between the internal program memory and the tablat. figure 6-4: reads from flash program memory example 6-1: reading a flash program memory word (even byte address) program memory (odd byte address) tblrd tablat tblptr = xxxxx1 fetch instruction register (ir) read register tblptr = xxxxx0 movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the word movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl read_word tblrd*+ ; read into tablat and increment movf tablat, w ; get data movwf word_even tblrd*+ ; read into tablat and increment movfw tablat, w ; get data movf word_odd
pic18f2585/2680/4585/4680 ds39625b-page 100 preliminary ? 2004 microchip technology inc. 6.4 erasing flash program memory the minimum erase block is 32 words or 64 bytes. only through the use of an external programmer, or through icsp control, can larger blocks of program memory be bulk erased. word erase in the flash array is not supported. when initiating an erase sequence from the micro- controller itself, a block of 64 bytes of program memory is erased. the most significant 16 bits of the tblptr<21:6> point to the block being erased. tblptr<5:0> are ignored. the eecon1 register commands the erase operation. the eepgd bit must be set to point to the flash program memory. the wren bit must be set to enable write operations. the free bit is set to select an erase operation. for protection, the write initiate sequence for eecon2 must be used. a long write is necessary for erasing the internal flash. instruction execution is halted while in a long write cycle. the long write will be terminated by the internal programming timer. 6.4.1 flash program memory erase sequence the sequence of events for erasing a block of internal program memory location is: 1. load table pointer register with address of row being erased. 2. set the eecon1 register for the erase operation:  set eepgd bit to point to program memory;  clear the cfgs bit to access program memory;  set wren bit to enable writes;  set free bit to enable the erase. 3. disable interrupts. 4. write 55h to eecon2. 5. write 0aah to eecon2. 6. set the wr bit. this will begin the row erase cycle. 7. the cpu will stall for duration of the erase (about 2 ms using internal timer). 8. re-enable interrupts. example 6-2: erasing a flash program memory row movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl erase_row bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable row erase operation bcf intcon, gie ; disable interrupts required movlw 55h sequence movwf eecon2 ; write 55h movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start erase (cpu stall) bsf intcon, gie ; re-enable interrupts
? 2004 microchip technology inc. preliminary ds39625b-page 101 pic18f2585/2680/4585/4680 6.5 writing to flash program memory the minimum programming block is 32 words or 64 bytes. word or byte programming is not supported. table writes are used internally to load the holding registers needed to program the flash memory. there are 64 holding registers used by the table writes for programming. since the table latch (tablat) is only a single byte, the tblwt instruction may need to be executed 64 times for each programming operation. all of the table write operations will essentially be short writes because only the holding registers are written. at the end of updating the 64 holding registers, the eecon1 register must be written to in order to start the programming operation with a long write. the long write is necessary for programming the internal flash. instruction execution is halted while in a long write cycle. the long write will be terminated by the internal programming timer. the eeprom on-chip timer controls the write time. the write/erase voltages are generated by an on-chip charge pump, rated to operate over the voltage range of the device. figure 6-5: table writes to flash program memory 6.5.1 flash program memory write sequence the sequence of events for programming an internal program memory location should be: 1. read 64 bytes into ram. 2. update data values in ram as necessary. 3. load table pointer register with address being erased. 4. execute the row erase procedure. 5. load table pointer register with address of first byte being written. 6. write the 64 bytes into the holding registers with auto-increment. 7. set the eecon1 register for the write operation:  set eepgd bit to point to program memory;  clear the cfgs bit to access program memory;  set wren to enable byte writes. 8. disable interrupts. 9. write 55h to eecon2. 10. write 0aah to eecon2. 11. set the wr bit. this will begin the write cycle. 12. the cpu will stall for duration of the write (about 2 ms using internal timer). 13. re-enable interrupts. 14. verify the memory (table read). this procedure will require about 18 ms to update one row of 64 bytes of memory. an example of the required code is given in example 6-3. note: the default value of the holding registers on device resets and after write operations is ffh. a write of ffh to a holding register does not modify that byte. this means that individual bytes of program memory may be modified, provided that the change does not attempt to change any bit from a ? 0 ? to a ? 1 ?. when modifying individual bytes, it is not necessary to load all 64 holding registers before executing a write operation. tblptr = xxxx3f tblptr = xxxxx1 tblptr = xxxxx0 tblptr = xxxxx2 program memory holding register holding register holding register holding register 8 8 8 8 tablat write register note: before setting the wr bit, the table pointer address needs to be within the intended address range of the 64 bytes in the holding register.
pic18f2585/2680/4585/4680 ds39625b-page 102 preliminary ? 2004 microchip technology inc. example 6-3: writing to flash program memory movlw d'64 ; number of bytes in erase block movwf counter movlw buffer_addr_high ; point to buffer movwf fsr0h movlw buffer_addr_low movwf fsr0l movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl read_block tblrd*+ ; read into tablat, and inc movf tablat, w ; get data movwf postinc0 ; store data decfsz counter ; done? bra read_block ; repeat modify_word movlw data_addr_high ; point to buffer movwf fsr0h movlw data_addr_low movwf fsr0l movlw new_data_low ; update buffer word movwf postinc0 movlw new_data_high movwf indf0 erase_block movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable row erase operation bcf intcon, gie ; disable interrupts movlw 55h required movwf eecon2 ; write 55h sequence movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start erase (cpu stall) bsf intcon, gie ; re-enable interrupts tblrd*- ; dummy read decrement movlw buffer_addr_high ; point to buffer movwf fsr0h movlw buffer_addr_low movwf fsr0l write_buffer_back movlw d?64 ; number of bytes in holding register movwf counter write_byte_to_hregs movfw postinc0, w ; get low byte of buffer data movwf tablat ; present data to table latch tblwt+* ; write data, perform a short write ; to internal tblwt holding register. decfsz counter ; loop until buffers are full bra write_word_to_hregs
? 2004 microchip technology inc. preliminary ds39625b-page 103 pic18f2585/2680/4585/4680 example 6-3: writing to flash program memory (continued) 6.5.2 write verify depending on the application, good programming practice may dictate that the value written to the memory should be verified against the original value. this should be used in applications where excessive writes can stress bits near the specification limit. 6.5.3 unexpected termination of write operation if a write is terminated by an unplanned event, such as loss of power or an unexpected reset, the memory location just programmed should be verified and repro- grammed if needed. if the write operation is interrupted by a mclr reset or a wdt time-out reset during normal operation, the user can check the wrerr bit and rewrite the location(s) as needed. 6.5.4 protection against spurious writes to protect against spurious writes to flash program memory, the write initiate sequence must also be followed. see section 24.0 ?special features of the cpu? for more detail. 6.6 flash program operation during code protection see section 24.5 ?program verification and code protection? for details on code protection of flash program memory. table 6-2: registers associated with program flash memory program_memory bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bcf intcon, gie ; disable interrupts movlw 55h required movwf eecon2 ; write 55h sequence movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start program (cpu stall) bsf intcon, gie ; re-enable interrupts bcf eecon1, wren ; disable write to memory name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page tblptru ? ? bit21 program memory table pointer upper byte (tblptr<20:16>) 49 tbpltrh program memory table pointer high byte (tblptr<15:8>) 49 tblptrl program memory table pointer high byte (tblptr<7:0>) 49 tablat program memory table latch 49 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 eecon2 eeprom control register 2 (not a physical register) 51 eecon1 eepgd cfgs ? free wrerr wren wr rd 51 ipr2 oscfip cmip (1) ? eeip bclip hlvdip tmr3ip eccp1ip (1) 51 pir2 oscfif cmif (1) ? eeif bclif hlvdif tmr3if eccp1if (1) 51 pie2 oscfie cmie (1) ? eeie bclie hlvdie tmr3ie eccp1ie (1) 52 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used during flash/eeprom access. note 1: these bits are available in pic18f4x8x devices and reserved in pic18f2x8x devices.
pic18f2585/2680/4585/4680 ds39625b-page 104 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 105 pic18f2585/2680/4585/4680 7.0 data eeprom memory the data eeprom is a nonvolatile memory array, separate from the data ram and program memory, that is used for long-term storage of program data. it is not directly mapped in either the register file or program memory space but is indirectly addressed through the special function registers (sfrs). the eeprom is readable and writable during normal operation over the entire v dd range. five sfrs are used to read and write to the data eeprom as well as the program memory. they are:  eecon1  eecon2  eedata  eeadr  eeadrh the data eeprom allows byte read and write. when interfacing to the data memory block, eedata holds the 8-bit data for read/write and the eeadrh:eeadr register pair holds the address of the eeprom location being accessed. the eeprom data memory is rated for high erase/write cycle endurance. a byte write automatically erases the location and writes the new data (erase-before-write). the write time is controlled by an on-chip timer; it will vary with voltage and temperature, as well as from chip to chip. please refer to parameter d122 (table 27-1 in section 27.0 ?electrical characteristics? ) for exact limits. 7.1 eeadr and eeadrh registers the eeadrh:eeadr register pair is used to address the data eeprom for read and write operations. eeadrh holds the two msbits of the address; the upper 6 bits are ignored. the 10-bit range of the pair can address a memory range of 1024 bytes (00h to 3ffh). 7.2 eecon1 and eecon2 registers access to the data eeprom is controlled by two registers: eecon1 and eecon2. these are the same registers which control access to the program memory and are used in a similar manner for the data eeprom. the eecon1 register (register 7-1) is the control register for data and program memory access. control bit eepgd determines if the access will be to program or data eeprom memory. when clear, operations will access the data eeprom memory. when set, program memory is accessed. control bit cfgs determines if the access will be to the configuration registers or to program memory/data eeprom memory. when set, subsequent operations access configuration registers. when cfgs is clear, the eepgd bit selects either program flash or data eeprom memory. the wren bit, when set, will allow a write operation. on power-up, the wren bit is clear. the wrerr bit is set in hardware when the wren bit is set and cleared when the internal programming timer expires and the write operation is complete. the wr control bit initiates write operations. the bit cannot be cleared, only set, in software; it is cleared in hardware at the completion of the write operation. control bits, rd and wr, start read and erase/write operations, respectively. these bits are set by firmware and cleared by hardware at the completion of the operation. the rd bit cannot be set when accessing program memory (eepgd = 1 ). program memory is read using table read instructions. see section 6.1 ?table reads and table writes? regarding table reads. the eecon2 register is not a physical register. it is used exclusively in the memory write and erase sequences. reading eecon2 will read all ? 0 ?s. note: during normal operation, the wrerr is read as ? 1 ?. this can indicate that a write operation was prematurely terminated by a reset, or a write operation was attempted improperly. note: the eeif interrupt flag bit (pir2<4>) is set when the write is complete. it must be cleared in software.
pic18f2585/2680/4585/4680 ds39625b-page 106 preliminary ? 2004 microchip technology inc. register 7-1: eecon1: data eeprom control register 1 r/w-x r/w-x u-0 r/w-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd cfgs ? free wrerr wren wr rd bit 7 bit 0 bit 7 eepgd: flash program or data eeprom memory select bit 1 = access flash program memory 0 = access data eeprom memory bit 6 cfgs: flash program/data eeprom or configuration select bit 1 = access configuration registers 0 = access flash program or data eeprom memory bit 5 unimplemented: read as ? 0 ? bit 4 free: flash row erase enable bit 1 = erase the program memory row addressed by tblptr on the next wr command (cleared by completion of erase operation) 0 = perform write only bit 3 wrerr: flash program/data eeprom error flag bit 1 = a write operation is prematurely terminated (any reset during self-timed programming in normal operation, or an improper write attempt) 0 = the write operation completed note: when a wrerr occurs, the eepgd and cfgs bits are not cleared. this allows tracing of the error condition. bit 2 wren: flash program/data eeprom write enable bit 1 = allows write cycles to flash program/data eeprom 0 = inhibits write cycles to flash program/data eeprom bit 1 wr: write control bit 1 = initiates a data eeprom erase/write cycle or a program memory erase cycle or write cycle (the operation is self-timed and the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software.) 0 = write cycle to the eeprom is complete bit 0 rd: read control bit 1 = initiates an eeprom read (read takes one cycle. rd is cleared in hardware. the rd bit can only be set (not cleared) in software. rd bit cannot be set when eepgd = 1 or cfgs = 1 .) 0 = does not initiate an eeprom read legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 107 pic18f2585/2680/4585/4680 7.3 reading the data eeprom memory to read a data memory location, the user must write the address to the eeadrh:eeadr register pair, clear the eepgd control bit (eecon1<7>) and then set control bit, rd (eecon1<0>). the data is available on the very next instruction cycle; therefore, the eedata register can be read by the next instruction. eedata will hold this value until another read operation, or until it is written to by the user (during a write operation). the basic process is shown in example 7-1. 7.4 writing to the data eeprom memory to write an eeprom data location, the address must first be written to the eeadrh:eeadr register pair and the data written to the eedata register. the sequence in example 7-2 must be followed to initiate the write cycle. the write will not begin if this sequence is not exactly followed (write 55h to eecon2, write 0aah to eecon2, then set wr bit) for each byte. it is strongly recommended that interrupts be disabled during this code segment. additionally, the wren bit in eecon1 must be set to enable writes. this mechanism prevents accidental writes to data eeprom due to unexpected code execution (i.e., runaway programs). the wren bit should be kept clear at all times, except when updating the eeprom. the wren bit is not cleared by hardware. after a write sequence has been initiated, eecon1, eeadrh:eeadr and eedata cannot be modified. the wr bit will be inhibited from being set unless the wren bit is set. the wren bit must be set on a previous instruction. both wr and wren cannot be set with the same instruction. at the completion of the write cycle, the wr bit is cleared in hardware and the eeprom interrupt flag bit (eeif) is set. the user may either enable this interrupt, or poll this bit. eeif must be cleared by software. 7.5 write verify depending on the application, good programming practice may dictate that the value written to the memory should be verified against the original value. this should be used in applications where excessive writes can stress bits near the specification limit. example 7-1: data eeprom read example 7-2: data eeprom write movlw data_ee_addrh ; movwf eeadrh ; upper bits of data memory address to read movlw data_ee_addr ; movwf eeadr ; lower bits of data memory address to read bcf eecon1, eepgd ; point to data memory bcf eecon1, cfgs ; access eeprom bsf eecon1, rd ; eeprom read movf eedata, w ; w = eedata movlw data_ee_addrh ; movwf eeadrh ; upper bits of data memory address to write movlw data_ee_addr ; movwf eeadr ; lower bits of data memory address to write movlw data_ee_data ; movwf eedata ; data memory value to write bcf eecon1, epgd ; point to data memory bcf eecon1, cfgs ; access eeprom bsf eecon1, wren ; enable writes bcf intcon, gie ; disable interrupts movlw 55h ; required movwf eecon2 ; write 55h sequence movlw 0aah ; movwf eecon2 ; write 0aah bsf eecon1, wr ; set wr bit to begin write bsf intcon, gie ; enable interrupts ; user code execution bcf eecon1, wren ; disable writes on write complete (eeif set)
pic18f2585/2680/4585/4680 ds39625b-page 108 preliminary ? 2004 microchip technology inc. 7.6 operation during code-protect data eeprom memory has its own code-protect bits in configuration words. external read and write operations are disabled if code protection is enabled. the microcontroller itself can both read and write to the internal data eeprom, regardless of the state of the code-protect configuration bit. refer to section 24.0 ?special features of the cpu? for additional information. 7.7 protection against spurious write there are conditions when the device may not want to write to the data eeprom memory. to protect against spurious eeprom writes, various mechanisms have been implemented. on power-up, the wren bit is cleared. in addition, writes to the eeprom are blocked during the power-up timer period (t pwrt , parameter 33). the write initiate sequence and the wren bit together help prevent an accidental write during brown-out, power glitch or software malfunction. 7.8 using the data eeprom the data eeprom is a high endurance, byte address- able array that has been optimized for the storage of frequently changing information (e.g., program variables or other data that are updated often). frequently changing values will typically be updated more often than specification d124. if this is not the case, an array refresh must be performed. for this reason, variables that change infrequently (such as constants, ids, calibration, etc.) should be stored in flash program memory. a simple data eeprom refresh routine is shown in example 7-3. example 7-3: data eeprom refresh routine note: if data eeprom is only used to store constants and/or data that changes rarely, an array refresh is likely not required. see specification d124. clrf eeadr ; start at address 0 clrf eeadrh ; bcf eecon1, cfgs ; set for memory bcf eecon1, eepgd ; set for data eeprom bcf intcon, gie ; disable interrupts bsf eecon1, wren ; enable writes loop ; loop to refresh array bsf eecon1, rd ; read current address movlw 55h ; movwf eecon2 ; write 55h movlw 0aah ; movwf eecon2 ; write 0aah bsf eecon1, wr ; set wr bit to begin write btfsc eecon1, wr ; wait for write to complete bra $-2 incfsz eeadr, f ; increment address bra loop ; not zero, do it again incfsz eeadrh, f ; increment the high address bra loop ; not zero, do it again bcf eecon1, wren ; disable writes bsf intcon, gie ; enable interrupts
? 2004 microchip technology inc. preliminary ds39625b-page 109 pic18f2585/2680/4585/4680 table 7-1: registers associated with data eeprom memory name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 eeadrh ? ? ? ? ? ? eeprom address register high byte 51 eeadr eeprom address register 51 eedata eeprom data register 51 eecon2 eeprom control register 2 (not a physical register) 51 eecon1 eepgd cfgs ? free wrerr wren wr rd 51 ipr2 oscfip cmip (1) ? eeip bclip hlvdip tmr3ip eccp1ip (1) 51 pir2 oscfif cmif (1) ? eeif bclif hlvdif tmr3if eccp1if (1) 51 pie2 oscfie cmie (1) ? eeie bclie hlvdie tmr3ie eccp1ie (1) 52 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used during flash/eeprom access. note 1: these bits are available in pic18f4x8x devices and reserved in pic18f2x8x devices.
pic18f2585/2680/4585/4680 ds39625b-page 110 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 111 pic18f2585/2680/4585/4680 8.0 8 x 8 hardware multiplier 8.1 introduction all pic18 devices include an 8 x 8 hardware multiplier as part of the alu. the multiplier performs an unsigned operation and yields a 16-bit result that is stored in the product register pair, prodh:prodl. the multiplier?s operation does not affect any flags in the status register. making multiplication a hardware operation allows it to be completed in a single instruction cycle. this has the advantages of higher computational throughput and reduced code size for multiplication algorithms and allows the pic18 devices to be used in many applica- tions previously reserved for digital signal processors. a comparison of various hardware and software multiply operations, along with the savings in memory and execution time, is shown in table 8-1. 8.2 operation example 8-1 shows the instruction sequence for an 8 x 8 unsigned multiplication. only one instruction is required when one of the arguments is already loaded in the wreg register. example 8-2 shows the sequence to do an 8 x 8 signed multiplication. to account for the signed bits of the arguments, each argument?s most significant bit (msb) is tested and the appropriate subtractions are done. example 8-1: 8 x 8 unsigned multiply routine example 8-2: 8 x 8 signed multiply routine table 8-1: performance comparison for various multiply operations movf arg1, w ; mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl movf arg1, w mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl btfsc arg2, sb ; test sign bit subwf prodh, f ; prodh = prodh ; - arg1 movf arg2, w btfsc arg1, sb ; test sign bit subwf prodh, f ; prodh = prodh ; - arg2 routine multiply method program memory (words) cycles (max) time @ 40 mhz @ 10 mhz @ 4 mhz 8 x 8 unsigned without hardware multiply 13 69 6.9 s27.6 s69 s hardware multiply 1 1 100 ns 400 ns 1 s 8 x 8 signed without hardware multiply 33 91 9.1 s36.4 s91 s hardware multiply 6 6 600 ns 2.4 s6 s 16 x 16 unsigned without hardware multiply 21 242 24.2 s96.8 s 242 s hardware multiply 28 28 2.8 s 11.2 s28 s 16 x 16 signed without hardware multiply 52 254 25.4 s 102.6 s 254 s hardware multiply 35 40 4.0 s16.0 s40 s
pic18f2585/2680/4585/4680 ds39625b-page 112 preliminary ? 2004 microchip technology inc. example 8-3 shows the sequence to do a 16 x 16 unsigned multiplication. equation 8-1 shows the algorithm that is used. the 32-bit result is stored in four registers (res3:res0). equation 8-1: 16 x 16 unsigned multiplication algorithm example 8-3: 16 x 16 unsigned multiply routine example 8-4 shows the sequence to do a 16 x 16 signed multiply. equation 8-2 shows the algorithm used. the 32-bit result is stored in four registers (res3:res0). to account for the signed bits of the arguments, the msb for each argument pair is tested and the appropriate subtractions are done. equation 8-2: 16 x 16 signed multiplication algorithm example 8-4: 16 x 16 signed multiply routine res3:res0 = arg1h:arg1l ? arg2h:arg2l = (arg1h ? arg2h ? 2 16 ) + (arg1h ? arg2l ? 2 8 ) + (arg1l ? arg2h ? 2 8 ) + (arg1l ? arg2l) movf arg1l, w mulwf arg2l ; arg1l * arg2l-> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h-> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l, w mulwf arg2h ; arg1l * arg2h-> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l-> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; res3:res0 = arg1h:arg1l ? arg2h:arg2l = (arg1h ? arg2h ? 2 16 ) + (arg1h ? arg2l ? 2 8 ) + (arg1l ? arg2h ? 2 8 ) + (arg1l ? arg2l) + (-1 ? arg2h<7> ? arg1h:arg1l ? 2 16 ) + (-1 ? arg1h<7> ? arg2h:arg2l ? 2 16 ) movf arg1l, w mulwf arg2l ; arg1l * arg2l -> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h -> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l,w mulwf arg2h ; arg1l * arg2h -> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l -> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; btfss arg2h, 7 ; arg2h:arg2l neg? bra sign_arg1 ; no, check arg1 movf arg1l, w ; subwf res2 ; movf arg1h, w ; subwfb res3 ; sign_arg1 btfss arg1h, 7 ; arg1h:arg1l neg? bra cont_code ; no, done movf arg2l, w ; subwf res2 ; movf arg2h, w ; subwfb res3 ; cont_code :
? 2004 microchip technology inc. preliminary ds39625b-page 113 pic18f2585/2680/4585/4680 9.0 interrupts the pic18f2585/2680/4585/4680 devices have multi- ple interrupt sources and an interrupt priority feature that allows each interrupt source to be assigned a high priority level or a low priority level. the high priority interrupt vector is at 000008h and the low priority interrupt vector is at 000018h. high priority interrupt events will interrupt any low priority interrupts that may be in progress. there are ten registers which are used to control interrupt operation. these registers are:  rcon intcon  intcon2  intcon3  pir1, pir2, pir3  pie1, pie2, pie3  ipr1, ipr2, ipr3 it is recommended that the microchip header files supplied with mplab ? ide be used for the symbolic bit names in these registers. this allows the assembler/ compiler to automatically take care of the placement of these bits within the specified register. each interrupt source has three bits to control its operation. the functions of these bits are:  flag bit to indicate that an interrupt event occurred  enable bit that allows program execution to branch to the interrupt vector address when the flag bit is set  priority bit to select high priority or low priority the interrupt priority feature is enabled by setting the ipen bit (rcon<7>). when interrupt priority is enabled, there are two bits which enable interrupts globally. setting the gieh bit (intcon<7>) enables all interrupts that have the priority bit set (high priority). setting the giel bit (intcon<6>) enables all interrupts that have the priority bit cleared (low priority). when the interrupt flag, enable bit and appropriate global interrupt enable bit are set, the interrupt will vector immediately to address 000008h or 000018h, depending on the priority bit setting. individual inter- rupts can be disabled through their corresponding enable bits. when the ipen bit is cleared (default state), the inter- rupt priority feature is disabled and interrupts are com- patible with picmicro ? mid-range devices. in compatibility mode, the interrupt priority bits for each source have no effect. intcon<6> is the peie bit, which enables/disables all peripheral interrupt sources. intcon<7> is the gie bit, which enables/disables all interrupt sources. all interrupts branch to address 000008h in compatibility mode. when an interrupt is responded to, the global interrupt enable bit is cleared to disable further interrupts. if the ipen bit is cleared, this is the gie bit. if interrupt priority levels are used, this will be either the gieh or giel bit. high priority interrupt sources can interrupt a low priority interrupt. low priority interrupts are not processed while high priority interrupts are in progress. the return address is pushed onto the stack and the pc is loaded with the interrupt vector address (000008h or 000018h). once in the interrupt service routine, the source(s) of the interrupt can be deter- mined by polling the interrupt flag bits. the interrupt flag bits must be cleared in software before re-enabling interrupts to avoid recursive interrupts. the ?return from interrupt? instruction, retfie , exits the interrupt routine and sets the gie bit (gieh or giel if priority levels are used), which re-enables interrupts. for external interrupt events, such as the int pins or the portb input change interrupt, the interrupt latency will be three to four instruction cycles. the exact latency is the same for one or two-cycle instructions. individual interrupt flag bits are set, regardless of the status of their corresponding enable bit or the gie bit. note: do not use the movff instruction to modify any of the interrupt control registers while any interrupt is enabled. doing so may cause erratic microcontroller behavior.
pic18f2585/2680/4585/4680 ds39625b-page 114 preliminary ? 2004 microchip technology inc. figure 9-1: interrupt logic tmr0ie gieh/gie giel/peie wake-up if in sleep mode interrupt to cpu vector to location 0008h int2if int2ie int2ip int1if int1ie int1ip tmr0if tmr0ie tmr0ip rbif rbie rbip ipen tmr0if tmr0ip int1if int1ie int1ip int2if int2ie int2ip rbif rbie rbip int0if int0ie giel/peie interrupt to cpu vector to location ipen ipe 0018h peripheral interrupt flag bit peripheral interrupt enable bit peripheral interrupt priority bit peripheral interrupt flag bit peripheral interrupt enable bit peripheral interrupt priority bit tmr1if tmr1ie tmr1ip xxxxif xxxxie xxxxip additional peripheral interrupts tmr1if tmr1ie tmr1ip high priority interrupt generation low priority interrupt generation xxxxif xxxxie xxxxip additional peripheral interrupts gie/geih
? 2004 microchip technology inc. preliminary ds39625b-page 115 pic18f2585/2680/4585/4680 9.1 intcon registers the intcon registers are readable and writable registers, which contain various enable, priority and flag bits. register 9-1: intcon: interrupt control register note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif bit 7 bit 0 bit 7 gie/gieh: global interrupt enable bit when ipen = 0 : 1 = enables all unmasked interrupts 0 = disables all interrupts when ipen = 1 : 1 = enables all high priority interrupts 0 = disables all high priority interrupts bit 6 peie/giel: peripheral interrupt enable bit when ipen = 0 : 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts when ipen = 1 : 1 = enables all low priority peripheral interrupts 0 = disables all low priority peripheral interrupts bit 5 tmr0ie: tmr0 overflow interrupt enable bit 1 = enables the tmr0 overflow interrupt 0 = disables the tmr0 overflow interrupt bit 4 int0ie: int0 external interrupt enable bit 1 = enables the int0 external interrupt 0 = disables the int0 external interrupt bit 3 rbie: rb port change interrupt enable bit 1 = enables the rb port change interrupt 0 = disables the rb port change interrupt bit 2 tmr0if: tmr0 overflow interrupt flag bit 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 int0if: int0 external interrupt flag bit 1 = the int0 external interrupt occurred (must be cleared in software) 0 = the int0 external interrupt did not occur bit 0 rbif: rb port change interrupt flag bit 1 = at least one of the rb7:rb4 pins changed state (must be cleared in software) 0 = none of the rb7:rb4 pins have changed state note: a mismatch condition will continue to set this bit. reading portb will end the mismatch condition and allow the bit to be cleared. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 116 preliminary ? 2004 microchip technology inc. register 9-2: intcon2: interrupt control register 2 r/w-1 r/w-1 r/w-1 r/w-1 u-0 r/w-1 u-0 r/w-1 rbpu intedg0 intedg1 intedg2 ?tmr0ip ?rbip bit 7 bit 0 bit 7 rbpu : portb pull-up enable bit 1 = all portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg0: external interrupt 0 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 5 intedg1: external interrupt 1 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 4 intedg2: external interrupt 2 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 3 unimplemented: read as ? 0 ? bit 2 tmr0ip: tmr0 overflow interrupt priority bit 1 = high priority 0 = low priority bit 1 unimplemented: read as ? 0 ? bit 0 rbip: rb port change interrupt priority bit 1 = high priority 0 = low priority legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
? 2004 microchip technology inc. preliminary ds39625b-page 117 pic18f2585/2680/4585/4680 register 9-3: intcon3: interrupt control register 3 r/w-1 r/w-1 u-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 int2ip int1ip ?int2ieint1ie ? int2if int1if bit 7 bit 0 bit 7 int2ip: int2 external interrupt priority bit 1 = high priority 0 = low priority bit 6 int1ip: int1 external interrupt priority bit 1 = high priority 0 = low priority bit 5 unimplemented: read as ? 0 ? bit 4 int2ie: int2 external interrupt enable bit 1 = enables the int2 external interrupt 0 = disables the int2 external interrupt bit 3 int1ie: int1 external interrupt enable bit 1 = enables the int1 external interrupt 0 = disables the int1 external interrupt bit 2 unimplemented: read as ? 0 ? bit 1 int2if: int2 external interrupt flag bit 1 = the int2 external interrupt occurred (must be cleared in software) 0 = the int2 external interrupt did not occur bit 0 int1if: int1 external interrupt flag bit 1 = the int1 external interrupt occurred (must be cleared in software) 0 = the int1 external interrupt did not occur legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
pic18f2585/2680/4585/4680 ds39625b-page 118 preliminary ? 2004 microchip technology inc. 9.2 pir registers the pir registers contain the individual flag bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are two peripheral interrupt request (flag) registers (pir1, pir2). register 9-4: pir1: peripheral interrupt request (flag) register 1 note 1: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit, gie (intcon<7>). 2: user software should ensure the appropri- ate interrupt flag bits are cleared prior to enabling an interrupt and after servicing that interrupt. r/w-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if bit 7 bit 0 bit 7 pspif: parallel slave port read/write interrupt flag bit (1) 1 = a read or a write operation has taken place (must be cleared in software) 0 = no read or write has occurred note 1: this bit is reserved on pic18f2x8x devices; always maintain this bit clear. bit 6 adif: a/d converter interrupt flag bit 1 = an a/d conversion completed (must be cleared in software) 0 = the a/d conversion is not complete bit 5 rcif: eusart receive interrupt flag bit 1 = the eusart receive buffer, rcreg, is full (cleared when rcreg is read) 0 = the eusart receive buffer is empty bit 4 txif: eusart transmit interrupt flag bit 1 = the eusart transmit buffer, txreg, is empty (cleared when txreg is written) 0 = the eusart transmit buffer is full bit 3 sspif: master synchronous serial port interrupt flag bit 1 = the transmission/reception is complete (must be cleared in software) 0 = waiting to transmit/receive bit 2 ccp1if: ccp1 interrupt flag bit capture mode: 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode: 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode: unused in this mode. bit 1 tmr2if: tmr2 to pr2 match interrupt flag bit 1 = tmr2 to pr2 match occurred (must be cleared in software) 0 = no tmr2 to pr2 match occurred bit 0 tmr1if: tmr1 overflow interrupt flag bit 1 = tmr1 register overflowed (must be cleared in software) 0 = mr1 register did not overflow legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 119 pic18f2585/2680/4585/4680 register 9-5: pir2: peripheral interrupt request (flag) register 2 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 oscfif cmif (1) ? eeif bclif hlvdif tmr3if eccp1if (1) bit 7 bit 0 bit 7 oscfif: oscillator fail interrupt flag bit 1 = system oscillator failed, clock input has changed to intosc (must be cleared in software) 0 = system clock operating bit 6 cmif: comparator interrupt flag bit (1) 1 = comparator input has changed (must be cleared in software) 0 = comparator input has not changed bit 5 unimplemented: read as ? 0 ? bit 4 eeif: data eeprom/flash write operation interrupt flag bit 1 = the write operation is complete (must be cleared in software) 0 = the write operation is not complete, or has not been started bit 3 bclif: bus collision interrupt flag bit 1 = a bus collision occurred (must be cleared in software) 0 = no bus collision occurred bit 2 hlvdif: high/low-voltage detect interrupt flag bit 1 = a low-voltage condition occurred (must be cleared in software) 0 = the device voltage is above the high/low-voltage detect trip point bit 1 tmr3if: tmr3 overflow interrupt flag bit 1 = tmr3 register overflowed (must be cleared in software) 0 = tmr3 register did not overflow bit 0 eccp1if: eccp1 interrupt flag bit (1) capture mode: 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode: 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode: unused in this mode. note 1: these bits are available in pic18f4x8x and reserved in pic18f2x8x devices. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 120 preliminary ? 2004 microchip technology inc. register 9-6: pir3: peripheral interrupt request (flag) register 3 mode 0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxif wakif errif txb2if txb1if (1) txb0if (1) rxb1if rxb0if mode 1, 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxif wakif errif txbnif txb1if (1) txb0if (1) rxbnif fifowmif bit 7 bit 0 bit 7 irxif: can invalid received message interrupt flag bit 1 = an invalid message has occurred on the can bus 0 = no invalid message on can bus bit 6 wakif: can bus activity wake-up interrupt flag bit 1 = activity on can bus has occurred 0 = no activity on can bus bit 5 errif: can bus error interrupt flag bit 1 = an error has occurred in the can module (multiple sources) 0 = no can module errors bit 4 when can is in mode 0: txb2if: can transmit buffer 2 interrupt flag bit 1 = transmit buffer 2 has completed transmission of a message and may be reloaded 0 = transmit buffer 2 has not completed transmission of a message when can is in mode 1 or 2: txbnif: any transmit buffer interrupt flag bit 1 = one or more transmit buffers have completed transmission of a message and may be reloaded 0 = no transmit buffer is ready for reload bit 3 txb1if: can transmit buffer 1 interrupt flag bit (1) 1 = transmit buffer 1 has completed transmission of a message and may be reloaded 0 = transmit buffer 1 has not completed transmission of a message bit 2 txb0if: can transmit buffer 0 interrupt flag bit (1) 1 = transmit buffer 0 has completed transmission of a message and may be reloaded 0 = transmit buffer 0 has not completed transmission of a message bit 1 when can is in mode 0: rxb1if: can receive buffer 1 interrupt flag bit 1 = receive buffer 1 has received a new message 0 = receive buffer 1 has not received a new message when can is in mode 1 or 2: rxbnif: any receive buffer interrupt flag bit 1 = one or more receive buffers has received a new message 0 = no receive buffer has received a new message bit 0 when can is in mode 0: rxb0if: can receive buffer 0 interrupt flag bit 1 = receive buffer 0 has received a new message 0 = receive buffer 0 has not received a new message when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmif: fifo watermark interrupt flag bit 1 = fifo high watermark is reached 0 = fifo high watermark is not reached note 1: in can mode 1 and 2, this bit is forced to ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 121 pic18f2585/2680/4585/4680 9.3 pie registers the pie registers contain the individual enable bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are two peripheral interrupt enable registers (pie1, pie2). when ipen = 0 , the peie bit must be set to enable any of these peripheral interrupts. register 9-7: pie1: peripheral interrupt enable register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie bit 7 bit 0 bit 7 pspie: parallel slave port read/write interrupt enable bit (1) 1 = enables the psp read/write interrupt 0 = disables the psp read/write interrupt note 1: this bit is reserved on pic18f2x8x devices; always maintain this bit clear. bit 6 adie: a/d converter interrupt enable bit 1 = enables the a/d interrupt 0 = disables the a/d interrupt bit 5 rcie: eusart receive interrupt enable bit 1 = enables the eusart receive interrupt 0 = disables the eusart receive interrupt bit 4 txie: eusart transmit interrupt enable bit 1 = enables the eusart transmit interrupt 0 = disables the eusart transmit interrupt bit 3 sspie: master synchronous serial port interrupt enable bit 1 = enables the mssp interrupt 0 = disables the mssp interrupt bit 2 ccp1ie: ccp1 interrupt enable bit 1 = enables the ccp1 interrupt 0 = disables the ccp1 interrupt bit 1 tmr2ie: tmr2 to pr2 match interrupt enable bit 1 = enables the tmr2 to pr2 match interrupt 0 = disables the tmr2 to pr2 match interrupt bit 0 tmr1ie: tmr1 overflow interrupt enable bit 1 = enables the tmr1 overflow interrupt 0 = disables the tmr1 overflow interrupt legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 122 preliminary ? 2004 microchip technology inc. register 9-8: pie2: peripheral interrupt enable register 2 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 oscfie cmie (1) ? eeie bclie hlvdie tmr3ie eccp1ie (2) bit 7 bit 0 bit 7 oscfie: oscillator fail interrupt enable bit 1 = enabled 0 =disabled bit 6 cmie: comparator interrupt enable bit (1) 1 = enabled 0 =disabled bit 5 unimplemented: read as ? 0 ? bit 4 eeie: data eeprom/flash write operation interrupt enable bit 1 = enabled 0 =disabled bit 3 bclie: bus collision interrupt enable bit 1 = enabled 0 =disabled bit 2 hlvdie: high/low-voltage detect interrupt enable bit 1 = enabled 0 =disabled bit 1 tmr3ie: tmr3 overflow interrupt enable bit 1 = enabled 0 =disabled bit 0 eccp1ie: eccp1 interrupt enable bit (2) 1 = enabled 0 =disabled note 1: this bit is available in pic18f4x8x devices and reserved in pic18f2x8x devices. 2: this bit is available in pic18f4x8x devices only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 123 pic18f2585/2680/4585/4680 register 9-9: pie3: peripheral interrupt enable register 3 mode 0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxie wakie errie txb2ie txb1ie (1) txb0ie (1) rxb1ie rxb0ie mode 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxie wakie errie txbnie txb1ie (1) txb0ie (1) rxbnie fifowmie bit 7 bit 0 bit 7 irxie: can invalid received message interrupt enable bit 1 = enable invalid message received interrupt 0 = disable invalid message received interrupt bit 6 wakie: can bus activity wake-up interrupt enable bit 1 = enable bus activity wake-up interrupt 0 = disable bus activity wake-up interrupt bit 5 errie: can bus error interrupt enable bit 1 = enable can bus error interrupt 0 = disable can bus error interrupt bit 4 when can is in mode 0: txb2ie: can transmit buffer 2 interrupt enable bit 1 = enable transmit buffer 2 interrupt 0 = disable transmit buffer 2 interrupt when can is in mode 1 or 2: txbnie: can transmit buffer interrupts enable bit 1 = enable transmit buffer interrupt; individual interrupt is enabled by txbie and bie0 0 = disable all transmit buffer interrupts bit 3 txb1ie: can transmit buffer 1 interrupt enable bit (1) 1 = enable transmit buffer 1 interrupt 0 = disable transmit buffer 1 interrupt bit 2 txb0ie: can transmit buffer 0 interrupt enable bit (1) 1 = enable transmit buffer 0 interrupt 0 = disable transmit buffer 0 interrupt bit 1 when can is in mode 0: rxb1ie: can receive buffer 1 interrupt enable bit 1 = enable receive buffer 1 interrupt 0 = disable receive buffer 1 interrupt when can is in mode 1 or 2: rxbnie: can receive buffer interrupts enable bit 1 = enable receive buffer interrupt; individual interrupt is enabled by bie0 0 = disable all receive buffer interrupts bit 0 when can is in mode 0: rxb0ie: can receive buffer 0 interrupt enable bit 1 = enable receive buffer 0 interrupt 0 = disable receive buffer 0 interrupt when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmie: fifo watermark interrupt enable bit 1 = enable fifo watermark interrupt 0 = disable fifo watermark interrupt note 1: in can mode 1 and 2, this bit is forced to ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 124 preliminary ? 2004 microchip technology inc. 9.4 ipr registers the ipr registers contain the individual priority bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are two peripheral interrupt priority registers (ipr1, ipr2). using the priority bits requires that the interrupt priority enable (ipen) bit be set. register 9-10: ipr1: peripheral interrupt priority register 1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip bit 7 bit 0 bit 7 pspip: parallel slave port read/write interrupt priority bit (1) 1 =high priority 0 = low priority note 1: this bit is reserved on pic18f2x8x devices; always maintain this bit set. bit 6 adip: a/d converter interrupt priority bit 1 =high priority 0 = low priority bit 5 rcip: eusart receive interrupt priority bit 1 =high priority 0 = low priority bit 4 txip: eusart transmit interrupt priority bit 1 =high priority 0 = low priority bit 3 sspip: master synchronous serial port interrupt priority bit 1 =high priority 0 = low priority bit 2 ccp1ip: ccp1 interrupt priority bit 1 =high priority 0 = low priority bit 1 tmr2ip: tmr2 to pr2 match interrupt priority bit 1 =high priority 0 = low priority bit 0 tmr1ip: tmr1 overflow interrupt priority bit 1 =high priority 0 = low priority legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 125 pic18f2585/2680/4585/4680 register 9-11: ipr2: peripheral interrupt priority register 2 r/w-1 r/w-1 u-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 oscfip cmip (1) ? eeip bclip hlvdip tmr3ip eccp1ip (2) bit 7 bit 0 bit 7 oscfip: oscillator fail interrupt priority bit 1 =high priority 0 = low priority bit 6 cmip: comparator interrupt priority bit (1) 1 =high priority 0 = low priority bit 5 unimplemented: read as ? 0 ? bit 4 eeip: data eeprom/flash write operation interrupt priority bit 1 =high priority 0 = low priority bit 3 bclip: bus collision interrupt priority bit 1 =high priority 0 = low priority bit 2 hlvdip: high/low-voltage detect interrupt priority bit 1 =high priority 0 = low priority bit 1 tmr3ip: tmr3 overflow interrupt priority bit 1 =high priority 0 = low priority bit 0 eccp1ip: eccp1 interrupt priority bit (2) 1 =high priority 0 = low priority note 1: this bit is available in pic18f4x8x devices and reserved in pic18f2x8x devices. 2: this bit is available in pic18f4x8x devices only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 126 preliminary ? 2004 microchip technology inc. register 9-12: ipr3: peripheral interrupt priority register 3 mode 0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 irxip wakip errip txb2ip txb1ip (1) txb0ip (1) rxb1ip rxb0ip mode 1, 2 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 irxip wakip errip txbnip txb1ip (1) txb0ip (1) rxbnip fifowmip bit 7 bit 0 bit 7 irxip: can invalid received message interrupt priority bit 1 = high priority 0 = low priority bit 6 wakip: can bus activity wake-up interrupt priority bit 1 = high priority 0 = low priority bit 5 errip: can bus error interrupt priority bit 1 = high priority 0 = low priority bit 4 when can is in mode 0: txb2ip: can transmit buffer 2 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1 or 2: txbnip: can transmit buffer interrupt priority bit 1 = high priority 0 = low priority bit 3 txb1ip: can transmit buffer 1 interrupt priority bit (1) 1 = high priority 0 = low priority bit 2 txb0ip: can transmit buffer 0 interrupt priority bit (1) 1 = high priority 0 = low priority bit 1 when can is in mode 0: rxb1ip: can receive buffer 1 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1 or 2: rxbnip: can receive buffer interrupts priority bit 1 = high priority 0 = low priority bit 0 when can is in mode 0: rxb0ip: can receive buffer 0 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmip: fifo watermark interrupt priority bit 1 = high priority 0 = low priority note 1: in can mode 1 and 2, this bit is forced to ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 127 pic18f2585/2680/4585/4680 9.5 rcon register the rcon register contains flag bits which are used to determine the cause of the last reset or wake-up from idle or sleep modes. rcon also contains the ipen bit which enables interrupt priorities. register 9-13: rcon: reset control re gister r/w-0 u-0 u-0 r/w-1 r-1 r-1 r/w-0 r/w-0 ipen sboren ?ri to pd por bor bit 7 bit 0 bit 7 ipen: interrupt priority enable bit 1 = enable priority levels on interrupts 0 = disable priority levels on interrupts (pic16cxxx compatibility mode) bit 6 sboren: bor software enable bit for details of bit operation, see register 4-1. bit 5 unimplemented: read as ? 0 ? bit 4 ri : reset instruction flag bit for details of bit operation, see register 4-1. bit 3 to : watchdog time-out flag bit for details of bit operation, see register 4-1. bit 2 pd : power-down detection flag bit for details of bit operation, see register 4-1. bit 1 por : power-on reset status bit for details of bit operation, see register 4-1. bit 0 bor : brown-out reset status bit for details of bit operation, see register 4-1. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 128 preliminary ? 2004 microchip technology inc. 9.6 intn pin interrupts external interrupts on the rb0/int0, rb1/int1 and rb2/int2 pins are edge-triggered. if the corresponding intedgx bit in the intcon2 register is set (= 1 ), the interrupt is triggered by a rising edge; if the bit is clear, the trigger is on the falling edge. when a valid edge appears on the rbx/intx pin, the corresponding flag bit intxf is set. this interrupt can be disabled by clear- ing the corresponding enable bit intxe. flag bit intxf must be cleared in software in the interrupt service routine before re-enabling the interrupt. all external interrupts (int0, int1 and int2) can wake-up the processor from the power managed modes, if bit intxe was set prior to going into power managed modes. if the global interrupt enable bit, gie, is set, the processor will branch to the interrupt vector following wake-up. interrupt priority for int1 and int2 is determined by the value contained in the interrupt priority bits, int1ip (intcon3<6>) and int2ip (intcon3<7>). there is no priority bit associated with int0. it is always a high priority interrupt source. 9.7 tmr0 interrupt in 8-bit mode (which is the default), an overflow in the tmr0 register (ffh 00h) will set flag bit tmr0if. in 16-bit mode, an overflow in the tmr0h:tmr0l regis- ter pair (ffffh 0000h) will set tmr0if. the interrupt can be enabled/disabled by setting/clearing enable bit tmr0ie (intcon<5>). interrupt priority for timer0 is determined by the value contained in the interrupt priority bit, tmr0ip (intcon2<2>). see section 11.0 ?timer0 module? for further details on the timer0 module. 9.8 portb interrupt-on-change an input change on portb<7:4> sets flag bit, rbif (intcon<0>). the interrupt can be enabled/disabled by setting/clearing enable bit, rbie (intcon<3>). interrupt priority for portb interrupt-on-change is determined by the value contained in the interrupt priority bit, rbip (intcon2<0>). 9.9 context saving during interrupts during interrupts, the return pc address is saved on the stack. additionally, the wreg, status and bsr registers are saved on the fast return stack. if a fast return from interrupt is not used (see section 5.3 ?data memory organization? ), the user may need to save the wreg, status and bsr registers on entry to the interrupt service routine. depending on the user?s application, other registers may also need to be saved. example 9-1 saves and restores the wreg, status and bsr registers during an interrupt service routine. example 9-1: saving status, wreg and bsr registers in ram movwf w_temp ; w_temp is in virtual bank movff status, status_temp ; status_temp located anywhere movff bsr, bsr_temp ; bsr_tmep located anywhere ; ; user isr code ; movff bsr_temp, bsr ; restore bsr movf w_temp, w ; restore wreg movff status_temp, status ; restore status
? 2004 microchip technology inc. preliminary ds39625b-page 129 pic18f2585/2680/4585/4680 10.0 i/o ports depending on the device selected and features enabled, there are up to five ports available. some pins of the i/o ports are multiplexed with an alternate function from the peripheral features on the device. in general, when a peripheral is enabled, that pin may not be used as a general purpose i/o pin. each port has three registers for its operation. these registers are:  tris register (data direction register)  port register (reads the levels on the pins of the device)  lat register (output latch) the data latch register (lat) is useful for read-modify- write operations on the value that the i/o pins are driving. a simplified model of a generic i/o port, without the interfaces to other peripherals, is shown in figure 10-1. figure 10-1: generic i/o port operation 10.1 porta, trisa and lata registers porta is an 8-bit wide, bidirectional port. the corresponding data direction register is trisa. setting a trisa bit (= 1 ) will make the corresponding porta pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisa bit (= 0 ) will make the corresponding porta pin an output (i.e., put the contents of the output latch on the selected pin). reading the porta register reads the status of the pins, whereas writing to it, will write to the port latch. the data latch register (lata) is also memory mapped. read-modify-write operations on the lata register read and write the latched output value for porta. the ra4 pin is multiplexed with the timer0 module clock input to become the ra4/t0cki pin. pins ra6 and ra7 are multiplexed with the main oscillator pins; they are enabled as oscillator or i/o pins by the selec- tion of the main oscillator in configuration register 1h (see section 24.1 ?configuration bits? for details). when they are not used as port pins, ra6 and ra7 and their associated tris and lat bits are read as ? 0 ?. the other porta pins are multiplexed with analog inputs, the analog v ref + and v ref - inputs and the comparator voltage reference output. the operation of pins ra3:ra0 and ra5 as a/d converter inputs is selected by clearing/setting the control bits in the adcon1 register (a/d control register 1). all other porta pins have ttl input levels and full cmos output drivers. the trisa register controls the direction of the ra pins, even when they are being used as analog inputs. the user must ensure the bits in the trisa register are maintained set when using them as analog inputs. example 10-1: initializing porta data bus wr lat wr tris rd port data latch tris latch rd tris input buffer i/o pin (1) q d ck q d ck en qd en rd lat or port note 1: i/o pins have diode protection to v dd and v ss . note: on a power-on reset, ra5 and ra3:ra0 are configured as analog inputs and read as ? 0 ?. ra4 is configured as a digital input. clrf porta ; initialize porta by ; clearing output ; data latches clrf lata ; alternate method ; to clear output ; data latches movlw 0fh ; configure a/d movwf adcon1 ; for digital inputs movwf 07h ; configure comparators movwf cmcon ; for digital input movlw 0cfh ; value used to ; initialize data ; direction movwf trisa ; set ra<3:0> as inputs ; ra<5:4> as outputs
pic18f2585/2680/4585/4680 ds39625b-page 130 preliminary ? 2004 microchip technology inc. table 10-1: porta i/o summary pin name function i/o tris buffer description ra0/an0/cv ref ra0 out 0 dig lata<0> data output. in 1 ttl porta<0> data input. an0 in 1 ana a/d input channel 0. enabled on por, this analog input overrides the digital input (read as clear ? low level). cv ref out x ana comparator voltage reference analog output. enabling this analog output overrides the digital i/o (read as clear ? low level). ra1/an1 ra1 out 0 dig lata<1> data output. in 1 ttl porta<1> data input. an1 in 1 ana a/d input channel 1. enabled on por, this analog input overrides the digital input (read as clear ? low level). ra2/an2/v ref -ra2 out 0 dig lata<2> data output. in 1 ttl porta<2> data input. an2 in 1 ana a/d input channel 2. enabled on por, this analog input overrides the digital input (read as clear ? low level). v ref -in 1 ana a/d and comparator negative voltage analog input. ra3/an3/v ref +ra3 out 0 dig lata<3> data output. in 1 ttl porta<3> data input. an3 in 1 ana a/d input channel 3. enabled on por, this analog input overrides the digital input (read as clear ? low level). v ref +in 1 ana a/d and comparator positive voltage analog input. ra4/t0cki ra4 out 0 dig lata<4> data output. in 1 ttl porta<4> data input. t0cki in 1 st timer0 clock input. ra5/an4/ss /hlvdin ra5 out 0 dig lata<5> data output. in 1 ttl porta<5> data input. an4 in 1 ana a/d input channel 4. enabled on por, this analog input overrides the digital input (read as clear ? low level). ss in 1 ttl slave select input for mssp. hlvdin in 1 ana high/low-voltage detect external trip point input. osc2/clko/ra6 osc2 out x ana output connection, selected by fosc3:fosc0 configuration bits. enabling osc2 overrides digital i/o. clko out x dig output connection, selected by fosc3:fosc0 configuration bits. enabling clko overrides digital i/o (f osc /4). ra6 out 0 dig lata<6> data output. in 1 ttl porta<6> data input. osc1/clki/ra7 osc1 in x ana main oscillator input connection, determined by fosc3:fosc0 configuration bits. enabling osc1 overrides digital i/o. clki in x ana main clock input connection, determined by fosc3:fosc0 configuration bits. enabling clki overrides digital i/o. ra7 out 0 dig lata<7> data output. in 1 ttl porta<7> data input. legend: pwr = power supply; out = output; in = input; ana = analog signal; dig = digital output; st = schmitt buffer input; ttl = ttl buffer input
? 2004 microchip technology inc. preliminary ds39625b-page 131 pic18f2585/2680/4585/4680 table 10-2: summary of registers associated with porta name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page porta ra7 (1) ra6 (1) ra5 ra4 ra3 ra2 ra1 ra0 52 lata lata7 (1) lata6 (1) lata data output register 52 trisa trisa7 (1) trisa6 (1) porta data direction register 52 adcon1 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 50 cmcon (2) c2out c1out c2inv c1inv cis cm2 cm1 cm0 51 cvrcon (2) cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by porta. note 1: ra7:ra6 and their associated latch and data direction bits are enabled as i/o pins based on oscillator configuration; otherwise, they are read as ? 0 ?. 2: these registers are unimplemented on pic18f2x8x devices.
pic18f2585/2680/4585/4680 ds39625b-page 132 preliminary ? 2004 microchip technology inc. 10.2 portb, trisb and latb registers portb is an 8-bit wide, bidirectional port. the corresponding data direction register is trisb. setting a trisb bit (= 1 ) will make the corresponding portb pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisb bit (= 0 ) will make the corresponding portb pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latb) is also memory mapped. read-modify-write operations on the latb register read and write the latched output value for portb. pins rb2 through rb3 are multiplexed with the ecan peripheral. refer to section 23.0 ?ecan? module? for proper settings of trisb when can is enabled. example 10-2: initializing portb each of the portb pins has a weak internal pull-up. a single control bit can turn on all the pull-ups. this is performed by clearing bit rbpu (intcon2<7>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on a power-on reset. four of the portb pins (rb7:rb4) have an interrupt- on-change feature. only pins configured as inputs can cause this interrupt to occur (i.e., any rb7:rb4 pin configured as an output is excluded from the interrupt- on-change comparison). the input pins (of rb7:rb4) are compared with the old value latched on the last read of portb. the ?mismatch? outputs of rb7:rb4 are ored together to generate the rb port change interrupt with flag bit, rbif (intcon<0>). this interrupt can wake the device from sleep. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of portb (except with the movff (any), portb instruction). this will end the mismatch condition. b) clear flag bit rbif. a mismatch condition will continue to set flag bit rbif. reading portb will end the mismatch condition and allow flag bit rbif to be cleared. the interrupt-on-change feature is recommended for wake-up on key depression operation and operations where portb is only used for the interrupt-on-change feature. polling of portb is not recommended while using the interrupt-on-change feature. note: on a power-on reset, rb4:rb0 are configured as analog inputs by default and read as ? 0 ?; rb7:rb5 are configured as digital inputs. by programming the configuration bit, pbaden (config3h<1>), rb4:rb0 will alternatively be configured as digital inputs on por. clrf portb ; initialize portb by ; clearing output ; data latches clrf latb ; alternate method ; to clear output ; data latches movlw 0eh ; set rb<4:0> as movwf adcon1 ; digital i/o pins ; (required if config bit ; pbaden is set) movlw 0cfh ; value used to ; initialize data ; direction movwf trisb ; set rb<3:0> as inputs ; rb<5:4> as outputs ; rb<7:6> as inputs
? 2004 microchip technology inc. preliminary ds39625b-page 133 pic18f2585/2680/4585/4680 table 10-3: portb i/o summary pin name function i/o tris buffer description rb0/int0/flt0/an10 rb0 out 0 dig latb<0> data output. in 1 ttl portb<0> data input. weak pull- up available only in this mode. int0 in 1 st external interrupt 0 input. flt0 in 1 st enhanced pwm fault input. an10 in 1 ana a/d input channel 10. enabled on por, this analog input overrides the digital input (read as clear ? low level). rb1/int1/an8 rb1 out 0 dig latb<1> data output. in 1 ttl portb<1> data input. weak pull- up available only in this mode. int1 in 1 st external interrupt 1 input. an8 in 1 ana a/d input channel 8. enabled on por, this analog input overrides the digital input (read as clear ? low level). rb2/int2/cantx rb2 out x dig latb<2> data output. in 1 ttl portb<2> data input. weak pull- up available only in this mode. int2 in 1 st external interrupt 2 input. cantx out 1 dig can transmit signal output. the can interface overrides the tris<2> control when enabled. rb3/canrx rb3 out 0 dig latb<3> data output. in 1 ttl portb<3> data input. weak pull- up available only in this mode. canrx in 1 st can receive signal input. pin must be configured as a digital input by setting trisb<3>. rb4/kbi0/an9 rb4 out 0 dig latb<4> data output. in 1 ttl portb<4> data input. weak pull- up available only in this mode. kbi0 in 1 ttl interrupt-on-pin change. an9 in 1 ana a/d input channel 9. enabled on por, this analog input overrides the digital input (read as clear ? low level). rb5/kbi1/pgm rb5 out 0 dig latb<5> data output. in 1 ttl portb<5> data input. weak pull- up available only in this mode. kbi1 in 1 ttl interrupt-on-pin change. pgm in x st low-voltage programming mode entry (icsp?). enabling this function overrides digital output. rb6/kbi2/pgc rb6 out 0 dig latb<6> data output. in 1 ttl portb<6> data input. weak pull- up available only in this mode. kbi2 in 1 ttl interrupt-on-pin change. pgc in x st low-voltage programming mode entry (icsp) clock input. rb7/kbi3/pgd rb7 out 0 dig latb<7> data output. in 1 ttl portb<7> data input. weak pull-up available only in this mode. kbi3 in 1 ttl interrupt-on-pin change. pgd out x dig low-voltage programming mode entry (icsp) clock output. in x st low-voltage programming mode entry (icsp) clock input. legend: pwr = power supply; out = output; in = input; ana = analog signal; dig = digital output; st = schmitt buffer input; ttl ? ttl buffer input
pic18f2585/2680/4585/4680 ds39625b-page 134 preliminary ? 2004 microchip technology inc. table 10-4: summary of registers associated with portb name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 52 latb latb data output register (read and write to data latch) 52 trisb portb data direction control register 52 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 intcon2 rbpu intedg0 intedg1 intedg2 ? tmr0ip ?rbip49 intcon3 int2ip int1ip ?int2ieint1ie ? int2if int1if 49 adcon1 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 50 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by portb.
? 2004 microchip technology inc. preliminary ds39625b-page 135 pic18f2585/2680/4585/4680 10.3 portc, trisc and latc registers portc is an 8-bit wide, bidirectional port. the corresponding data direction register is trisc. setting a trisc bit (= 1 ) will make the corresponding portc pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisc bit (= 0 ) will make the corresponding portc pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latc) is also memory mapped. read-modify-write operations on the latc register read and write the latched output value for portc. portc is multiplexed with several peripheral functions (table 10-5). the pins have schmitt trigger input buffers. when enabling peripheral functions, care should be taken in defining tris bits for each portc pin. some peripherals override the tris bit to make a pin an output, while other peripherals override the tris bit to make a pin an input. the user should refer to the corresponding peripheral section for the correct tris bit settings. the contents of the trisc register are affected by peripheral overrides. reading trisc always returns the current contents, even though a peripheral device may be overriding one or more of the pins. example 10-3: initializing portc note: on a power-on reset, these pins are configured as digital inputs. clrf portc ; initialize portc by ; clearing output ; data latches clrf latc ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisc ; set rc<3:0> as inputs ; rc<5:4> as outputs ; rc<7:6> as inputs
pic18f2585/2680/4585/4680 ds39625b-page 136 preliminary ? 2004 microchip technology inc. table 10-5: portc i/o summary pin name function i/o tris buffer description rc0/t1oso/ t13cki rc0 out 0 dig latc<0> data output. in 1 st portc<0> data input. t1oso out x ana timer1 oscillator output ? overri des the tris<0> control when enabled. t13cki in 1 st timer1/timer3 clock input. rc1/t1osi rc1 out 0 dig latc<1> data output. in 1 st portc<1> data input. t1osi in x ana timer1 oscillator input ? overrides the tris<1> control when enabled. rc2/ccp1 rc2 out 0 dig latc<2> data output. in 1 st portc<2> data input. ccp1 out 0 dig ccp1 compare output. in 1 st ccp1 capture input. rc3/sck/scl rc3 out 0 dig latc<3> data output. in 1 st portc<3> data input. sck out 0 dig spi? clock output (mssp module) ? must have tris set to ? 1 ? to allow the mssp module to control the bidirectional communication. in 1 st spi clock input (mssp module). scl out 0 dig i 2 c?/sm bus clock output (mssp module) ? must have tris set to ? 1 ? to allow the mssp module to control the bidirectional communication. in 1 i 2 c/smb i 2 c/sm bus clock input. rc4/sdi/sda rc4 out 0 dig latc<4> data output. in 1 st portc<4> data input. sdi in 1 st spi data input (mssp module). sda out 1 dig i 2 c/sm bus data output (mssp module) ? must have tris set to ? 1 ? to allow the mssp module to control the bidirectional communication. in 1 i 2 c/smb i 2 c/sm bus data input (mssp module) ? must have tris set to ? 1 ? to allow the mssp module to control the bidirectional communication. rc5/sdo rc5 out 0 dig latc<5> data output. in 1 st portc<5> data input. sdo out 0 dig spi data output (mssp module). rc6/tx/ck rc6 out 0 dig latc<6> data output. in 1 st portc<6> data input. tx out 0 dig eusart data output. ck out 1 dig eusart synchronous clock output ? must have tris set to ? 1 ? to enable eusart to control the bidirectional communication. in 1 st eusart synchronous clock input. rc7/rx/dt rc7 out 0 dig latc<7> data output. in 1 st portc<7> data input. rx in 1 st eusart asynchronous data input. dt out 1 dig eusart synchronous data output ? must have tris set to ? 1 ? to enable eusart to control the bidirectional communication. in 1 st eusart synchronous data input. legend: pwr = power supply; out = output; in = input; ana = analog signal; dig = digital output; st = schmitt buffer input; ttl = ttl buffer input
? 2004 microchip technology inc. preliminary ds39625b-page 137 pic18f2585/2680/4585/4680 table 10-6: summary of registers associated with portc name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 52 latc portc data output register 52 trisc portc data direction register 52
pic18f2585/2680/4585/4680 ds39625b-page 138 preliminary ? 2004 microchip technology inc. 10.4 portd, trisd and latd registers portd is an 8-bit wide, bidirectional port. the corre- sponding data direction register is trisd. setting a trisd bit (= 1 ) will make the corresponding portd pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisd bit (= 0 ) will make the corresponding portd pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latd) is also memory mapped. read-modify-write operations on the latd register read and write the latched output value for portd. all pins on portd are implemented with schmitt trigger input buffers. each pin is individually configurable as an input or output. three of the portd pins are multiplexed with outputs p1a, p1b, p1c and p1d of the enhanced ccp1 (eccp1) module. the operation of these additional pwm output pins is covered in greater detail in section 16.0 ?enhanced capture/compare/pwm (eccp1) module? . portd can also be configured as an 8-bit wide micro- processor port (parallel slave port) by setting control bit, pspmode (trise<4>). in this mode, the input buffers are ttl. see section 10.6 ?parallel slave port? for additional information on the parallel slave port (psp). example 10-4: initializing portd note: portd is only available on pic18f4x8x devices. note: on a power-on reset, these pins are configured as digital inputs. note: when the enhanced pwm mode is used with either dual or quad outputs, the psp functions of portd are automatically disabled. clrf portd ; initialize portd by ; clearing output ; data latches clrf latd ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisd ; set rd<3:0> as inputs ; rd<5:4> as outputs ; rd<7:6> as inputs
? 2004 microchip technology inc. preliminary ds39625b-page 139 pic18f2585/2680/4585/4680 table 10-7: portd i/o summary pin name function i/o tris buffer description rd0/psp0/ c1in+ rd0 out 0 dig latd<0> data output. in 1 st portd<0> data input. psp0 out x dig parallel slave port (psp) data output (ove rrides the tris<0> control when enabled). in x ttl parallel slave port (psp) data input (ove rrides the tris<0> control when enabled). c1in+ in 1 ana comparator 1 positive input b. default on por. this analog input overrides the digital input (read as clear ? low level). rd1/psp1/ c1in- rd1 out 0 dig latd<1> data output. in 1 st portd<1> data input. psp1 out x dig parallel slave port (psp) data output (ove rrides the tris<1> control when enabled). in x ttl parallel slave port (psp) data input (ove rrides the tris<1> control when enabled). c1in- in 1 ana comparator 1 negative input. default on por. this analog input overrides the digital input (read as clear ? low level). rd2/psp2/ c2in+ rd2 out 0 dig latd<2> data output. in 1 st portd<2> data input. psp2 out x dig parallel slave port (psp) data output (ove rrides the tris<2> control when enabled). in x ttl parallel slave port (psp) data input (ove rrides the tris<2> control when enabled). c2in+ in 1 ana comparator 2 positive input. default on por. this analog input overrides the digital input (read as clear ? low level). rd3/psp3/ c2in- rd3 out 0 dig latd<3> data output. in 1 st portd<3> data input. psp3 out x dig parallel slave port (psp) data output (ove rrides the tris<3> control when enabled). in x ttl parallel slave port (psp) data input (ove rrides the tris<3> control when enabled). c2in- in 1 ana comparator 2 negative input. default input on por. this analog input overrides the digital input (read as clear ? low level). rd4/psp4/ eccp1/p1a rd4 out 0 dig latd<4> data output. in 1 st portd<4> data input. psp4 out x dig parallel slave port (psp) data output (ove rrides the tris<4> control when enabled). in x ttl parallel slave port (psp) data input (ove rrides the tris<4> control when enabled). eccp1 out 0 dig eccp1 compare output. in 1 st eccp1 capture input. p1a out 0 dig eccp1 enhanced pwm output, channel a. rd5/psp5/ p1b rd5 out 0 dig latd<5> data output. in 1 st portd<5> data input. psp5 out x dig parallel slave port (psp) data output (ove rrides the tris<5> control when enabled). in x ttl parallel slave port (psp) data input (ove rrides the tris<5> control when enabled). p1b out 0 dig eccp1 enhanced pwm output, channel b. rd6/psp6/ p1c rd6 out 0 dig latd<6> data output. in 1 st portd<6> data input. psp6 out x dig parallel slave port (psp) data output (ove rrides the tris<6> control when enabled). in x ttl parallel slave port (psp) data input (ove rrides the tris<6> control when enabled). p1c out 0 dig eccp1 enhanced pwm output, channel c. rd7/psp7/ p1d rd7 out 0 dig latd<7> data output. in 1 st portd<7> data input. psp7 out x dig parallel slave port (psp) data output (ove rrides the tris<7> control when enabled). in x ttl parallel slave port (psp) data input (ove rrides the tris<7> control when enabled). p1d out 0 dig eccp1 enhanced pwm output, channel d. legend: pwr = power supply; out = output; in = input; ana = analog signal; dig = digital output; st = schmitt buffer input; ttl = ttl buffer input
pic18f2585/2680/4585/4680 ds39625b-page 140 preliminary ? 2004 microchip technology inc. table 10-8: summary of registers associated with portd name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page portd (1) rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 52 latd (1) latd data output register 52 trisd (1) portd data direction register 52 trise (1) ibf obf ibov pspmode ? porte data direction bits 52 eccp1con (1) epwm1m1 epwm1m0 edc1b1 edc1b0 eccp1m3 eccp1m2 eccp1m1 eccp1m0 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by portd. note 1: these registers are available on pic18f4x8x devices only.
? 2004 microchip technology inc. preliminary ds39625b-page 141 pic18f2585/2680/4585/4680 10.5 porte, trise and late registers depending on the particular pic18f2585/2680/4585/ 4680 device selected, porte is implemented in two different ways. for pic18f4x8x devices, porte is a 4-bit wide port. three pins (re0/rd /an5, re1/wr /an6/c1out and re2/cs /an7/c2out) are individually configurable as inputs or outputs. these pins have schmitt trigger input buffers. when selected as an analog input, these pins will read as ? 0 ?s. the corresponding data direction register is trise. setting a trise bit (= 1 ) will make the corresponding porte pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trise bit (= 0 ) will make the corresponding porte pin an output (i.e., put the contents of the output latch on the selected pin). trise controls the direction of the re pins, even when they are being used as analog inputs. the user must make sure to keep the pins configured as inputs when using them as analog inputs. the upper four bits of the trise register also control the operation of the parallel slave port. their operation is explained in register 10-1. the data latch register (late) is also memory mapped. read-modify-write operations on the late register, read and write the latched output value for porte. the fourth pin of porte (mclr /v pp /re3) is an input only pin. its operation is controlled by the mclre configuration bit. when selected as a port pin (mclre = 0 ), it functions as a digital input only pin. as such, it does not have tris or lat bits associated with its operation. otherwise, it functions as the device?s master clear input. in either configuration, re3 also functions as the programming voltage input during programming. example 10-5: initializing porte 10.5.1 porte in 28-pin devices for pic18f2x8x devices, porte is only available when master clear functionality is disabled (mclre = 0 ). in these cases, porte is a single bit, input only port comprised of re3 only. the pin operates as previously described. note: on a power-on reset, re2:re0 are configured as analog inputs. note: on a power-on reset, re3 is enabled as a digital input only if master clear functionality is disabled. clrf porte ; initialize porte by ; clearing output ; data latches clrf late ; alternate method ; to clear output ; data latches movlw 0ah ; configure a/d movwf adcon1 ; for digital inputs movlw 03h ; value used to ; initialize data ; direction movlw 07h ; turn off movwf cmcon ; comparators movwf trisc ; set re<0> as inputs ; re<1> as outputs ; re<2> as inputs
pic18f2585/2680/4585/4680 ds39625b-page 142 preliminary ? 2004 microchip technology inc. register 10-1: trise register (pic18f4x8x devices only) r-0 r-0 r/w-0 r/w-0 u-0 r/w-1 r/w-1 r/w-1 ibf obf ibov pspmode ? trise2 trise1 trise0 bit 7 bit 0 bit 7 ibf: input buffer full status bit 1 = a word has been received and waiting to be read by the cpu 0 = no word has been received bit 6 obf: output buffer full status bit 1 = the output buffer still holds a previously written word 0 = the output buffer has been read bit 5 ibov: input buffer overflow detect bit (in microprocessor mode) 1 = a write occurred when a previously input word has not been read (must be cleared in software) 0 = no overflow occurred bit 4 pspmode: parallel slave port mode select bit 1 = parallel slave port mode 0 = general purpose i/o mode bit 3 unimplemented: read as ? 0 ? bit 2 trise2: re2 direction control bit 1 = input 0 = output bit 1 trise1: re1 direction control bit 1 = input 0 = output bit 0 trise0: re0 direction control bit 1 = input 0 = output legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 143 pic18f2585/2680/4585/4680 table 10-9: porte i/o summary table 10-10: summary of registers associated with porte pin name function i/o tris buffer description re0/rd /an5 re0 out 0 dig late<0> data output. in 1 st porte<0> data input. rd in 1 ttl psp read enable input. an5 in 1 ana a/d input channel 5. enabled on por, this analog input overrides the digital input (read as clear ? low level). re1/wr /an6/c1out re1 out 0 dig late<1> data output. in 1 st porte<1> data input. wr in 1 ttl psp write enable input. an6 in 1 ana a/d input channel 6. enabled on por, this analog input overrides the digital input (read as clear ? low level). c1out out 0 dig comparator 1 output. re2/cs /an7/c2out re2 out 0 dig late<2> data output. in 1 st porte<2> data input. cs in 1 ttl psp chip select input. an7 in 1 ana a/d input channel 7. enabled on por, this analog input overrides the digital input (read as clear ? low level). c2out out 0 dig comparator 2 output. mclr /v pp /re3 mclr in x st external reset input. disabled when mclre configuration bit is ? 1 ?. v pp in x ana high-voltage detection; used by icsp? operation. re3 in 1 st porte<3> data input. disabled when mclre configuration bit is ? 0 ?. legend: pwr = power supply; out = output; in = input; ana = analog signal; dig = digital output; st = schmitt buffer input; ttl = ttl buffer input name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page porte (3) ? ? ? ?re3 (1,2) re2 re1 re0 52 late (2) ? ? ? ? ? late data output register 52 trise (3) ibf obf ibov pspmode ? trise2 trise1 trise0 52 adcon1 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 50 cmcon (3) c2out c1out c2inv c1inv cis cm2 cm1 cm0 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by porte. note 1: implemented only when master clear functionality is disabled (mclre configuration bit = 0 ). 2: re3 is the only porte bit implemented on both pic18f 2x8x and pic18f4x8x devices. all other bits are implemented only when porte is implemented (i.e., pic18f4x8x devices). 3: these registers are unimplemented on pic18f2x8x devices.
pic18f2585/2680/4585/4680 ds39625b-page 144 preliminary ? 2004 microchip technology inc. 10.6 parallel slave port in addition to its function as a general i/o port, portd can also operate as an 8-bit wide parallel slave port (psp) or microprocessor port. psp operation is controlled by the 4 upper bits of the trise register (register 10-1). setting control bit, pspmode (trise<4>), enables psp operation, as long as the enhanced ccp1 (eccp1) module is not operating in dual output or quad output pwm mode. in slave mode, the port is asynchronously readable and writable by the external world. the psp can directly interface to an 8-bit micro- processor data bus. the external microprocessor can read or write the portd latch as an 8-bit latch. setting the control bit pspmode enables the porte i/o pins to become control inputs for the microprocessor port. when set, port pin re0 is the rd input, re1 is the wr input and re2 is the cs (chip select) input. for this functionality, the corresponding data direction bits of the trise register (trise<2:0>) must be configured as inputs (set). the a/d port configuration bits, pfcg3:pfcg0 (adcon1<3:0>), must also be set to ? 1010 ?. a write to the psp occurs when both the cs and wr lines are first detected low and ends when either are detected high. the pspif and ibf flag bits are both set when the write ends. a read from the psp occurs when both the cs and rd lines are first detected low. the data in portd is read out and the obf bit is set. if the user writes new data to portd to set obf, the data is immediately read out; however, the obf bit is not set. when either the cs or rd lines are detected high, the portd pins return to the input state and the pspif bit is set. user applications should wait for pspif to be set before servicing the psp; when this happens, the ibf and obf bits can be polled and the appropriate action taken. the timing for the control signals in write and read modes is shown in figure 10-3 and figure 10-4, respectively. figure 10-2: portd and porte block diagram (parallel slave port) note: the parallel slave port is only available on pic18f4x8x devices. data bus wr latd rdx pin q d ck en qd en rd portd one bit of portd set interrupt flag pspif (pir1<7>) read chip select write rd cs wr ttl ttl ttl ttl or wr portd rd latd data latch note: i/o pins have diode protection to v dd and v ss . porte pins
? 2004 microchip technology inc. preliminary ds39625b-page 145 pic18f2585/2680/4585/4680 figure 10-3: parallel slave port write waveforms figure 10-4: parallel slave port read waveforms table 10-11: registers associated with parallel slave port name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page portd (1) rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 52 latd (1) portd data latch register (read and write to data latch) 52 trisd (1) portd data direction control register 52 porte (1) ? ? ? ? re3 re2 re1 re0 52 late (1) ? ? ? ? ? late data output bits 52 trise (1) ibf obf ibov pspmode ? trise2 trise1 trise0 52 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir1 pspif (2) adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie (2) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr1 pspip (2) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 adcon1 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 50 cmcon (1) c2out c1out c2inv c1inv cis cm2 cm1 cm0 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the parallel slave port. note 1: these registers are available on pic18f4x8x devices only. 2: these registers are unimplemented on pic18f2x8x devices and read as ? 0 ?. q1 q2 q3 q4 cs q1 q2 q3 q4 q1 q2 q3 q4 wr rd ibf obf pspif portd<7:0> q1 q2 q3 q4 cs q1 q2 q3 q4 q1 q2 q3 q4 wr ibf pspif rd obf portd<7:0>
pic18f2585/2680/4585/4680 ds39625b-page 146 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 147 pic18f2585/2680/4585/4680 11.0 timer0 module the timer0 module incorporates the following features:  software selectable operation as a timer or counter in both 8-bit or 16-bit modes  readable and writable registers  dedicated 8-bit, software programmable prescaler  selectable clock source (internal or external)  edge select for external clock  interrupt-on-overflow the t0con register (register 11-1) controls all aspects of the module?s operation, including the prescale selection. it is both readable and writable. a simplified block diagram of the timer0 module in 8-bit mode is shown in figure 11-1. figure 11-2 shows a simplified block diagram of the timer0 module in 16-bit mode. register 11-1: t0con: timer0 control register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 bit 7 bit 0 bit 7 tmr0on: timer0 on/off control bit 1 = enables timer0 0 = stops timer0 bit 6 t08bit : timer0 8-bit/16-bit control bit 1 = timer0 is configured as an 8-bit timer/counter 0 = timer0 is configured as a 16-bit timer/counter bit 5 t0cs : timer0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (clko) bit 4 t0se : timer0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa : timer0 prescaler assignment bit 1 = timer0 prescaler is not assigned. timer0 clock input bypasses prescaler. 0 = timer0 prescaler is assigned. timer0 clock input comes from prescaler output. bit 2-0 t0ps2:t0ps0 : timer0 prescaler select bits 111 = 1:256 prescale value 110 = 1:128 prescale value 101 = 1:64 prescale value 100 = 1:32 prescale value 011 = 1:16 prescale value 010 = 1:8 prescale value 001 = 1:4 prescale value 000 = 1:2 prescale value legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 148 preliminary ? 2004 microchip technology inc. 11.1 timer0 operation timer0 can operate as either a timer or a counter; the mode is selected by clearing the t0cs bit (t0con<5>). in timer mode, the module increments on every clock by default unless a different prescaler value is selected (see section 11.3 ?prescaler? ). if the tmr0 register is written to, the increment is inhib- ited for the following two instruction cycles. the user can work around this by writing an adjusted value to the tmr0 register. the counter mode is selected by setting the t0cs bit (= 1 ). in counter mode, timer0 increments either on every rising or falling edge of pin ra4/t0cki. the incrementing edge is determined by the timer0 source edge select bit, t0se (t0con<4>). clearing this bit selects the rising edge. restrictions on the external clock input are discussed below. an external clock source can be used to drive timer0; however, it must meet certain requirements to ensure that the external clock can be synchronized with the internal phase clock (t osc ). there is a delay between synchronization and the onset of incrementing the timer/counter. 11.2 timer0 reads and writes in 16-bit mode tmr0h is not the actual high byte of timer0 in 16-bit mode; it is actually a buffered version of the real high byte of timer0, which is not directly readable nor writ- able (refer to figure 11-2). tmr0h is updated with the contents of the high byte of timer0 during a read of tmr0l. this provides the ability to read all 16 bits of timer0 without having to verify that the read of the high and low byte were valid, due to a rollover between successive reads of the high and low byte. similarly, a write to the high byte of timer0 must also take place through the tmr0h buffer register. the high byte is updated with the contents of tmr0h when a write occurs to tmr0l. this allows all 16 bits of timer0 to be updated at once. figure 11-1: timer0 block diagram (8-bit mode) figure 11-2: timer0 block diagram (16-bit mode) note: upon reset, timer0 is enabled in 8-bit mode with clock input from t0cki max. prescale. t0cki pin t0se 0 1 1 0 t0cs f osc /4 programmable prescaler sync with internal clocks tmr0l (2 t cy delay) internal data bus psa t0ps2:t0ps0 set tmr0if on overflow 3 8 8 note: upon reset, timer0 is enabled in 8-bit mode with clock input from t0cki max. prescale. t0cki pin t0se 0 1 1 0 t0cs f osc /4 programmable prescaler sync with internal clocks tmr0l (2 t cy delay) internal data bus 8 psa t0ps2:t0ps0 set tmr0if on overflow 3 tmr0 tmr0h high byte 8 8 8 read tmr0l write tmr0l 8
? 2004 microchip technology inc. preliminary ds39625b-page 149 pic18f2585/2680/4585/4680 11.3 prescaler an 8-bit counter is available as a prescaler for the timer0 module. the prescaler is not directly readable or writable; its value is set by the psa and t0ps2:t0ps0 bits (t0con<3:0>) which determine the prescaler assignment and prescale ratio. clearing the psa bit assigns the prescaler to the timer0 module. when it is assigned, prescale values from 1:2 through 1:256 in power-of-2 increments are selectable. when assigned to the timer0 module, all instructions writing to the tmr0 register (e.g., clrf tmr0 , movwf tmr0 , bsf tmr0 , etc.) clear the prescaler count. 11.3.1 switching prescaler assignment the prescaler assignment is fully under software control and can be changed ?on-the-fly? during program execution. 11.4 timer0 interrupt the tmr0 interrupt is generated when the tmr0 register overflows from ffh to 00h in 8-bit mode, or from ffffh to 0000h in 16-bit mode. this overflow sets the tmr0if flag bit. the interrupt can be masked by clearing the tmr0ie bit (intcon<5>). before re- enabling the interrupt, the tmr0if bit must be cleared in software by the interrupt service routine. since timer0 is shut down in sleep mode, the tmr0 interrupt cannot awaken the processor from sleep. table 11-1: registers associated with timer0 note: writing to tmr0 when the prescaler is assigned to timer0 will clear the prescaler count but will not change the prescaler assignment. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page tmr0l timer0 module low byte register 50 tmr0h timer0 module high byte register 50 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 t0con tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 50 trisa ? porta data direction register 52 legend: x = unknown, u = unchanged, ? = unimplemented locations, read as ? 0 ?. shaded cells are not used by timer0.
pic18f2585/2680/4585/4680 ds39625b-page 150 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 151 pic18f2585/2680/4585/4680 12.0 timer1 module the timer1 timer/counter module incorporates these features:  software selectable operation as a 16-bit timer or counter  readable and writable 8-bit registers (tmr3h and tmr3l)  selectable clock source (internal or external) with device clock or timer1 oscillator internal options  interrupt-on-overflow  module reset on ccp1 special event trigger  device clock status flag (t1run) a simplified block diagram of the timer1 module is shown in figure 12-1. a block diagram of the module?s operation in read/write mode is shown in figure 12-2. the module incorporates its own low-power oscillator to provide an additional clocking option. the timer1 oscillator can also be used as a low-power clock source for the microcontroller in power managed operation. timer1 can also be used to provide real-time clock (rtc) functionality to applications with only a minimal addition of external components and code overhead. timer1 is controlled through the t1con control register (register 12-1). it also contains the timer1 oscillator enable bit (t1oscen). timer1 can be enabled or disabled by setting or clearing control bit, tmr1on (t1con<0>). register 12-1: t1con: timer1 control register r/w-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 rd16 t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on bit 7 bit 0 bit 7 rd16: 16-bit read/write mode enable bit 1 = enables register read/write of timer1 in one 16-bit operation 0 = enables register read/write of timer1 in two 8-bit operations bit 6 t1run: timer1 system clock status bit 1 = device clock is derived from timer1 oscillator 0 = device clock is derived from another source bit 5-4 t1ckps1:t1ckps0: timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t1oscen: timer1 oscillator enable bit 1 = timer1 oscillator is enabled 0 = timer1 oscillator is shut off the oscillator inverter and feedback resistor are turned off to eliminate power drain. bit 2 t1sync : timer1 external clock input synchronization select bit when tmr1cs = 1 : 1 = do not synchronize external clock input 0 = synchronize external clock input when tmr1cs = 0 : this bit is ignored. timer1 uses the internal clock when tmr1cs = 0 . bit 1 tmr1cs: timer1 clock source select bit 1 = external clock from pin rc0/t1oso/t13cki (on the rising edge) 0 = internal clock (f osc /4) bit 0 tmr1on: timer1 on bit 1 = enables timer1 0 = stops timer1 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 152 preliminary ? 2004 microchip technology inc. 12.1 timer1 operation timer1 can operate in one of these modes: timer  synchronous counter  asynchronous counter the operating mode is determined by the clock select bit, tmr3cs (t3con<1>). when tmr3cs is cleared (= 0 ), timer3 increments on every internal instruction cycle (fosc/4). when the bit is set, timer3 increments on every rising edge of the timer1 external clock input or the timer1 oscillator, if enabled. when timer1 is enabled, the rc1/t1osi and rc0/ t1oso/t13cki pins become inputs. this means the values of trisc<1:0> are ignored and the pins are read as ? 0 ?. figure 12-1: timer1 block diagram figure 12-2: timer1 block diagram (16-bit read/write mode) t1sync tmr1cs t1ckps1:t1ckps0 sleep input t1oscen (1) f osc /4 internal clock on/off prescaler 1, 2, 4, 8 synchronize detect 1 0 2 t1oso/t13cki t1osi 1 0 tmr1on tmr1l set tmr1if on overflow tmr1 high byte clear tmr1 (ccp1 special event trigger) timer1 oscillator note 1: when enable bit t1oscen is cleared, the inverter and f eedback resistor are turned off to eliminate power drain. on/off timer1 t1sync tmr1cs t1ckps1:t1ckps0 sleep input t1oscen (1) f osc /4 internal clock prescaler 1, 2, 4, 8 synchronize detect 1 0 2 t1oso/t13cki t1osi note 1: when enable bit t1oscen is cleared, the inverter and feedbac k resistor are turned off to eliminate power drain. 1 0 tmr1l internal data bus 8 set tmr1if on overflow tmr1 tmr1h high byte 8 8 8 read tmr1l write tmr1l 8 tmr1on clear tmr1 (ccp1 special event trigger) timer1 oscillator on/off timer1
? 2004 microchip technology inc. preliminary ds39625b-page 153 pic18f2585/2680/4585/4680 12.2 timer1 16-bit read/write mode timer1 can be configured for 16-bit reads and writes (see figure 12-2). when the rd16 control bit (t1con<7>) is set, the address for tmr1h is mapped to a buffer register for the high byte of timer1. a read from tmr1l will load the contents of the high byte of timer1 into the timer1 high byte buffer register. this provides the user with the ability to accurately read all 16 bits of timer1 without having to determine whether a read of the high byte, followed by a read of the low byte, has become invalid due to a rollover between reads. a write to the high byte of timer1 must also take place through the tmr1h buffer register. the timer1 high byte is updated with the contents of tmr1h when a write occurs to tmr1l. this allows a user to write all 16 bits to both the high and low bytes of timer1 at once. the high byte of timer1 is not directly readable or writable in this mode. all reads and writes must take place through the timer1 high byte buffer register. writes to tmr1h do not clear the timer1 prescaler. the prescaler is only cleared on writes to tmr1l. 12.3 timer1 oscillator an on-chip crystal oscillator circuit is incorporated between pins t1osi (input) and t1oso (amplifier output). it is enabled by setting the timer1 oscillator enable bit, t1oscen (t1con<3>). the oscillator is a low-power circuit rated for 32 khz crystals. it will continue to run during all power managed modes. the circuit for a typical lp oscillator is shown in figure 12-3. table 12-1 shows the capacitor selection for the timer1 oscillator. the user must provide a software time delay to ensure proper start-up of the timer1 oscillator. figure 12-3: external components for the timer1 lp oscillator table 12-1: capacitor selection for the timer oscillator (1,2,3,4) 12.3.1 using timer1 as a clock source the timer1 oscillator is also available as a clock source in power managed modes. by setting the clock select bits, scs1:scs0 (osccon<1:0>), to ? 01 ?, the device switches to sec_run mode; both the cpu and peripherals are clocked from the timer1 oscillator. if the idlen bit (osccon<7>) is cleared and a sleep instruction is executed, the device enters sec_idle mode. additional details are available in section 3.0 ?power managed modes? . whenever the timer1 oscillator is providing the clock source, the timer1 system clock status flag, t1run (t1con<6>), is set. this can be used to determine the controller?s current clocking mode. it can also indicate the clock source being currently used by the fail-safe clock monitor. if the clock monitor is enabled and the timer1 oscillator fails while providing the clock, polling the t1run bit will indicate whether the clock is being provided by the timer1 oscillator or another source. 12.3.2 low-power timer1 option the timer1 oscillator can operate at two distinct levels of power consumption based on device configuration. when the lpt1osc configuration bit is set, the timer1 oscillator operates in a low-power mode. when lpt1osc is not set, timer1 operates at a higher power level. power consumption for a particular mode is rela- tively constant, regardless of the device?s operating mode. the default timer1 configuration is the higher power mode. as the low-power timer1 mode tends to be more sensitive to interference, high noise environments may cause some oscillator instability. the low-power option is, therefore, best suited for low noise applications where power conservation is an important design consideration. note: see the notes with table 12-1 for additiona l information about capacitor selection. c1 c2 xtal pic18fxxxx t1osi t1oso 32.768 khz 33 pf 33 pf osc type freq c1 c2 lp 32 khz 27 pf 27 pf note 1: microchip suggests these values as a starting point in validating the oscillator circuit. 2: higher capacitance increases the stability of the oscillator but also increases the start-up time. 3: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. 4: capacitor values are for design guidance only.
pic18f2585/2680/4585/4680 ds39625b-page 154 preliminary ? 2004 microchip technology inc. 12.3.3 timer1 oscillator layout considerations the timer1 oscillator circuit draws very little power during operation. due to the low-power nature of the oscillator, it may also be sensitive to rapidly changing signals in close proximity. the oscillator circuit, shown in figure 12-3, should be located as close as possible to the microcontroller. there should be no circuits passing within the oscillator circuit boundaries other than v ss or v dd . if a high-speed circuit must be located near the oscilla- tor (such as the ccp1 pin in output compare or pwm mode, or the primary oscillator using the osc2 pin), a grounded guard ring around the oscillator circuit, as shown in figure 12-4, may be helpful when used on a single-sided pcb or in addition to a ground plane. figure 12-4: oscillator circuit with grounded guard ring 12.4 timer1 interrupt the tmr1 register pair (tmr1h:tmr1l) increments from 0000h to ffffh and rolls over to 0000h. the timer1 interrupt, if enabled, is generated on overflow, which is latched in interrupt flag bit, tmr1if (pir1<0>). this interrupt can be enabled or disabled by setting or clearing the timer1 interrupt enable bit, tmr1ie (pie1<0>). 12.5 resetting timer1 using the ccp1 special event trigger if either of the ccp1 modules is configured in compare mode to generate a special event trigger (ccp1m3:ccp1m0 or ccp2m3:ccp2m0 = 1011 ), this signal will reset timer1. the trigger from eccp1 will also start an a/d conversion if the a/d module is enabled (see section 15.3.4 ?special event trigger? for more information.). the module must be configured as either a timer or a synchronous counter to take advantage of this feature. when used this way, the ccpr1h:ccpr1l register pair effectively becomes a period register for timer1. if timer1 is running in asynchronous counter mode, this reset operation may not work. in the event that a write to timer1 coincides with a special event trigger, the write operation will take precedence. 12.6 using timer1 as a real-time clock adding an external lp oscillator to timer1 (such as the one described in section 12.3 ?timer1 oscillator? above) gives users the option to include rtc function- ality to their applications. this is accomplished with an inexpensive watch crystal to provide an accurate time base and several lines of application code to calculate the time. when operating in sleep mode and using a battery or supercapacitor as a power source, it can completely eliminate the need for a separate rtc device and battery backup. the application code routine, rtcisr , shown in example 12-1, demonstrates a simple method to increment a counter at one-second intervals using an interrupt service routine. incrementing the tmr1 register pair to overflow triggers the interrupt and calls the routine, which increments the seconds counter by one; additional counters for minutes and hours are incremented as the previous counter overflow. since the register pair is 16 bits wide, counting up to overflow the register directly from a 32.768 khz clock would take 2 seconds. to force the overflow at the required one-second intervals, it is necessary to pre- load it. the simplest method is to set the msb of tmr1h with a bsf instruction. note that the tmr1l register is never preloaded or altered; doing so may introduce cumulative error over many cycles. for this method to be accurate, timer1 must operate in asynchronous mode and the timer1 overflow interrupt must be enabled (pie1<0> = 1 ) as shown in the routine, rtcinit . the timer1 oscillator must also be enabled and running at all times. v dd osc1 v ss osc2 rc0 rc1 rc2 note: not drawn to scale. note: the special event triggers from the eccp1 module will not set the tmr1if interrupt flag bit (pir1<0>).
? 2004 microchip technology inc. preliminary ds39625b-page 155 pic18f2585/2680/4585/4680 example 12-1: implementing a real-time clock using a timer1 interrupt service table 12-2: registers associated with timer1 as a timer/counter rtcinit movlw 80h ; preload tmr1 register pair movwf tmr1h ; for 1 second overflow clrf tmr1l movlw b?00001111? ; configure for external clock, movwf t1osc ; asynchronous operation, external oscillator clrf secs ; initialize timekeeping registers clrf mins ; movlw .12 movwf hours bsf pie1, tmr1ie ; enable timer1 interrupt return rtcisr bsf tmr1h, 7 ; preload for 1 sec overflow bcf pir1, tmr1if ; clear interrupt flag incf secs, f ; increment seconds movlw .59 ; 60 seconds elapsed? cpfsgt secs return ; no, done clrf secs ; clear seconds incf mins, f ; increment minutes movlw .59 ; 60 minutes elapsed? cpfsgt mins return ; no, done clrf mins ; clear minutes incf hours, f ; increment hours movlw .23 ; 24 hours elapsed? cpfsgt hours return ; no, done movlw .01 ; reset hours to 1 movwf hours return ; done name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir1 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 tmr1l timer1 register, low byte 50 tmr1h timer1 register, high byte 50 t1con rd16 t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 50 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer1 module. note 1: these bits are unimplemented on pic18f2x8x devices; always maintain these bits clear.
pic18f2585/2680/4585/4680 ds39625b-page 156 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 157 pic18f2585/2680/4585/4680 13.0 timer2 module the timer2 module timer incorporates the following features:  8-bit timer and period registers (tmr2 and pr2, respectively)  readable and writable (both registers)  software programmable prescaler (1:1, 1:4 and 1:16)  software programmable postscaler (1:1 through 1:16)  interrupt on tmr2-to-pr2 match  optional use as the shift clock for the mssp module the module is controlled through the t2con register (register 13-1), which enables or disables the timer and configures the prescaler and postscaler. timer2 can be shut off by clearing control bit, tmr2on (t2con<2>), to minimize power consumption. a simplified block diagram of the module is shown in figure 13-1. 13.1 timer2 operation in normal operation, tmr2 is incremented from 00h on each clock (f osc /4). a 2-bit counter/prescaler on the clock input gives direct input, divide-by-4 and divide-by- 16 prescale options; these are selected by the prescaler control bits, t2ckps1:t2ckps0 (t2con<1:0>). the value of tmr2 is compared to that of the period register, pr2, on each clock cycle. when the two values match, the comparator generates a match signal as the timer output. this signal also resets the value of tmr2 to 00h on the next cycle and drives the output counter/ postscaler (see section 13.2 ?timer2 interrupt? ). the tmr2 and pr2 registers are both directly readable and writable. the tmr2 register is cleared on any device reset, while the pr2 register initializes at ffh. both the prescaler and postscaler counters are cleared on the following events:  a write to the tmr2 register  a write to the t2con register  any device reset (power-on reset, mclr reset, watchdog timer reset or brown-out reset) tmr2 is not cleared when t2con is written. register 13-1: t2con: time r2 control register u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6-3 t2outps3:t2outps0 : timer2 output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale    1111 = 1:16 postscale bit 2 tmr2on : timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps1:t2ckps0 : timer2 clock prescale select bits 00 = prescaler is 1 01 = prescaler is 4 1x = prescaler is 16 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 158 preliminary ? 2004 microchip technology inc. 13.2 timer2 interrupt timer2 also can generate an optional device interrupt. the timer2 output signal (tmr2-to-pr2 match) provides the input for the 4-bit output counter/ postscaler. this counter generates the tmr2 match interrupt flag which is latched in tmr2if (pir1<1>). the interrupt is enabled by setting the tmr2 match interrupt enable bit, tmr2ie (pie1<1>). a range of 16 postscale options (from 1:1 through 1:16 inclusive) can be selected with the postscaler control bits, t2outps3:t2outps0 (t2con<6:3>). 13.3 tmr2 output the unscaled output of tmr2 is available primarily to the ccp1 modules, where it is used as a time base for operations in pwm mode. timer2 can be optionally used as the shift clock source for the mssp module operating in spi mode. additional information is provided in section 17.0 ?master synchronous serial port (mssp) module? . figure 13-1: timer2 block diagram table 13-1: registers associated with timer2 as a timer/counter comparator tmr2 output tmr2 postscaler prescaler pr2 2 f osc /4 1:1 to 1:16 1:1, 1:4, 1:16 4 t2outps3:t2outps0 t2ckps1:t2ckps0 set tmr2if internal data bus 8 reset tmr2/pr2 8 8 (to pwm or mssp) match name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir1 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 tmr2 timer2 register 50 t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 50 pr2 timer2 period register 50 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer2 module. note 1: these bits are unimplemented on pic18f2x8x devices; always maintain these bits clear.
? 2004 microchip technology inc. preliminary ds39625b-page 159 pic18f2585/2680/4585/4680 14.0 timer3 module the timer3 module timer/counter incorporates these features:  software selectable operation as a 16-bit timer or counter  readable and writable 8-bit registers (tmr3h and tmr3l)  selectable clock source (internal or external) with device clock or timer1 oscillator internal options  interrupt-on-overflow  module reset on ccp1 special event trigger a simplified block diagram of the timer3 module is shown in figure 14-1. a block diagram of the module?s operation in read/write mode is shown in figure 14-2. the timer3 module is controlled through the t3con register (register 14-1). it also selects the clock source options for the ccp1 modules (see section 15.1.1 ?ccp1 modules and timer resources? for more information). register 14-1: t3con: time r3 control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 rd16 t3eccp1 (1) t3ckps1 t3ckps0 t3ccp1 (1) t3sync tmr3cs tmr3on bit 7 bit 0 bit 7 rd16: 16-bit read/write mode enable bit 1 = enables register read/write of timer3 in one 16-bit operation 0 = enables register read/write of timer3 in two 8-bit operations bit 6,3 t3eccp1:t3ccp1: timer3 and timer1 to eccp1/ccp1 enable bits (1) 1x = timer3 is the capture/compare clock source for both ccp1 and eccp1 modules 01 = timer3 is the capture/compare clock source for eccp1; timer1 is the capture/compare clock source for ccp1 00 = timer1 is the capture/compare clock source for both ccp1 and eccp1 modules note 1: these bits are available on pic18f4x8x devices only. bit 5-4 t3ckps1:t3ckps0 : timer3 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 2 t3sync : timer3 external clock input synchronization control bit (not usable if the device clock comes from timer1/timer3.) when tmr3cs = 1 : 1 = do not synchronize external clock input 0 = synchronize external clock input when tmr3cs = 0 : this bit is ignored. timer3 uses the internal clock when tmr3cs = 0 . bit 1 tmr3cs: timer3 clock source select bit 1 = external clock input from timer1 oscillator or t13cki (on the rising edge after the first falling edge) 0 = internal clock (f osc /4) bit 0 tmr3on: timer3 on bit 1 = enables timer3 0 = stops timer3 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 160 preliminary ? 2004 microchip technology inc. 14.1 timer3 operation timer3 can operate in one of three modes: timer  synchronous counter  asynchronous counter the operating mode is determined by the clock select bit, tmr3cs (t3con<1>). when tmr3cs is cleared (= 0 ), timer3 increments on every internal instruction cycle (f osc /4). when the bit is set, timer3 increments on every rising edge of the timer1 external clock input or the timer1 oscillator if enabled. as with timer1, the rc1/t1osi and rc0/t1oso/ t13cki pins become inputs when the timer1 oscillator is enabled. this means the values of trisc<1:0> are ignored and the pins are read as ? 0 ?. figure 14-1: timer3 block diagram figure 14-2: timer3 block diagram (16-bit read/write mode) t3sync tmr3cs t3ckps1:t3ckps0 sleep input t1oscen (1) f osc /4 internal clock prescaler 1, 2, 4, 8 synchronize detect 1 0 2 t1oso/t13cki t1osi 1 0 tmr3on tmr3l set tmr3if on overflow tmr3 high byte timer1 oscillator note 1: when enable bit t1oscen is cleared, the inverter and feedback resistor are turned off to eliminate power drain. on/off timer3 ccp1/eccp1 special event trigger tccpx clear tmr3 t3sync tmr3cs t3ckps1:t3ckps0 sleep input t1oscen (1) f osc /4 internal clock prescaler 1, 2, 4, 8 synchronize detect 1 0 2 t1oso/t13cki t1osi note 1: when enable bit t1oscen is cleared, the inverter and feedback resistor are turned off to eliminate power drain. 1 0 tmr3l internal data bus 8 set tmr3if on overflow tmr3 tmr3h high byte 8 8 8 read tmr1l write tmr1l 8 tmr3on ccp1/eccp1 special event trigger timer1 oscillator on/off timer3 timer1 clock input tccpx clear tmr3
? 2004 microchip technology inc. preliminary ds39625b-page 161 pic18f2585/2680/4585/4680 14.2 timer3 16-bit read/write mode timer3 can be configured for 16-bit reads and writes (see figure 14-2). when the rd16 control bit (t3con<7>) is set, the address for tmr3h is mapped to a buffer register for the high byte of timer3. a read from tmr3l will load the contents of the high byte of timer3 into the timer3 high byte buffer register. this provides the user with the ability to accurately read all 16 bits of timer1 without having to determine whether a read of the high byte, followed by a read of the low byte, has become invalid due to a rollover between reads. a write to the high byte of timer3 must also take place through the tmr3h buffer register. the timer3 high byte is updated with the contents of tmr3h when a write occurs to tmr3l. this allows a user to write all 16 bits to both the high and low bytes of timer3 at once. the high byte of timer3 is not directly readable or writable in this mode. all reads and writes must take place through the timer3 high byte buffer register. writes to tmr3h do not clear the timer3 prescaler. the prescaler is only cleared on writes to tmr3l. 14.3 using the timer1 oscillator as the timer3 clock source the timer1 internal oscillator may be used as the clock source for timer3. the timer1 oscillator is enabled by setting the t1oscen (t1con<3>) bit. to use it as the timer3 clock source, the tmr3cs bit must also be set. as previously noted, this also configures timer3 to increment on every rising edge of the oscillator source. the timer1 oscillator is described in section 12.0 ?timer1 module? . 14.4 timer3 interrupt the tmr3 register pair (tmr3h:tmr3l) increments from 0000h to ffffh and overflows to 0000h. the timer3 interrupt, if enabled, is generated on overflow and is latched in the interrupt flag bit, tmr3if (pir2<1>). this interrupt can be enabled or disabled by setting or clearing the timer3 interrupt enable bit, tmr3ie (pie2<1>). 14.5 resetting timer3 using the eccp1 special event trigger if the eccp1 module is configured to generate a special event trigger in compare mode (eccp1m3:eccp1m0 = 1011 ), this signal will reset timer3. it will also start an a/d conversion if the a/d module is enabled (see section 15.3.4 ?special event trigger? for more information.). the module must be configured as either a timer or synchronous counter to take advantage of this feature. when used this way, the eccpr1h:eccpr1l register pair effectively becomes a period register for timer3. if timer3 is running in asynchronous counter mode, the reset operation may not work. in the event that a write to timer3 coincides with a special event trigger from a ccp1 module, the write will take precedence. table 14-1: registers associated with timer3 as a timer/counter note: the special event triggers from the eccp1 module will not set the tmr3if interrupt flag bit (pir1<0>). name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir2 oscfif cmif (2) ? eeif bclif hlvdif tmr3if eccp1if (2) 51 pie2 oscfie cmie (2) ? eeie bclie hlvdie tmr3ie eccp1ie (2) 52 ipr2 oscfip cmip (2) ? eeip bclip hlvdip tmr3ip eccp1ip (2) 51 tmr3l timer3 register, low byte 51 tmr3h timer3 register, high byte 51 t1con rd16 t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 50 t3con rd16 t3eccp1 (1) t3ckps1 t3ckps0 t3ccp1 (1) t3sync tmr3cs tmr3on 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer3 module. note 1: these bits are available in pic18f4x8x devices only. 2: these bits are available in pic18f4x8x devices and reserved in pic18f2x8x devices.
pic18f2585/2680/4585/4680 ds39625b-page 162 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 163 pic18f2585/2680/4585/4680 15.0 capture/compare/pwm (ccp1) modules pic18f2585/2680 devices have one ccp1 module. pic18f4585/4680 devices have two ccp1 (capture/compare/pwm) modules. ccp1, discussed in this chapter, implements standard capture, compare and pulse-width modulation (pwm) modes. eccp1 implements an enhanced pwm mode. the eccp1 implementation is discussed in section 16.0 ?enhanced capture/compare/pwm (eccp1) module? . the ccp1 module contains a 16-bit register which can operate as a 16-bit capture register, a 16-bit compare register or a pwm master/slave duty cycle register. for the sake of clarity, all ccp1 module operation in the following sections is described with respect to ccp1, but is equally applicable to eccp1. capture and compare operations described in this chapter apply to all standard and enhanced ccp1 modules. the operations of pwm mode, described in section 15.4 ?pwm mode? , apply to eccp1 only. register 15-1: ccp1con: capture/compare/pwm control register u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dc1b1:dc1b0 : pwm duty cycle bit 1 and bit 0 for ccp1 module capture mode: unused. compare mode : unused. pwm mode: these bits are the two lsbs (bit 1 and bit 0) of the 10-bit pwm duty cycle. the eight msbs (dc19:dc12) of the duty cycle are found in eccpr1l. bit 3-0 ccp1m3:ccp1m0 : ccp1 module mode select bits 0000 = capture/compare/pwm disabled (resets ccp1 module) 0001 = reserved 0010 = compare mode, toggle output on match (ccp1if bit is set) 0011 = reserved 0100 = capture mode, every falling edge or can message received (time-stamp) (1) 0101 = capture mode, every rising edge or can message received (time-stamp) (1) 0110 = capture mode, every 4th rising edge or every 4th can message received (time-stamp) (1) 0111 = capture mode, every 16th rising edge or every 16th can message received (time-stamp) (1) 1000 = compare mode: initialize ccp1 pin low; on compare match, force ccp1 pin high (ccpif bit is set) 1001 = compare mode: initialize ccp pin high; on compare match, force ccp1 pin low (ccpif bit is set) 1010 = compare mode: generate software interrupt on compare match (ccpif bit is set, ccp1 pin reflects i/o state) 1011 = compare mode: trigger special event, reset timer (tmr1 or tmr3, ccp1if bit is set) 11xx =pwm mode note 1: selected by cancap (ciocon<4>) bit; overrides the ccp1 input pin source. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 164 preliminary ? 2004 microchip technology inc. 15.1 ccp1 module configuration each capture/compare/pwm module is associated with a control register (ccp1con or eccp1con) and a data register (ccpr1 or eccpr1). the data register, in turn, is comprised of two 8-bit registers: ccpr1l or eccpr1l (low byte) and ccpr1h or eccpr1h (high byte). all registers are both readable and writable. 15.1.1 ccp1 modules and timer resources the ccp1 modules utilize timers 1, 2 or 3, depending on the mode selected. timer1 and timer3 are available to modules in capture or compare modes, while timer2 is available for modules in pwm mode. table 15-1: ccp1 mode ? timer resource the assignment of a particular timer to a module is determined by the timer-to-ccp1/eccp1 enable bits in the t3con register (register 14-1). both modules may be active at any given time and may share the same timer resource if they are configured to operate in the same mode (capture/compare or pwm) at the same time. the interactions between the two modules are summarized in figure 15-1 and figure 15-2. table 15-2: interactions between ccp1 and eccp1 for timer resources ccp1/eccp1 mode timer resource capture compare pwm timer1 or timer3 timer1 or timer3 timer2 ccp1 mode eccp1 mode interaction capture capture each module can use tmr1 or tmr3 as the time base. time base can be different for each ccp1. capture compare ccp1 can be configured for the special event trigger to reset tmr1 or tmr3 (depending upon which time base is used). automatic a/d conversions on trigger event can also be done. operation of ccp1 could be affected if it is using the same timer as a time base. compare capture ccp1 can be configured for the special event trigger to reset tmr1 or tmr3 (depending upon which time base is used). operation of ccp1 could be affected if it is using the same timer as a time base. compare compare either module can be configured for the special event trigger to reset the time base. automatic a/d conversions on eccp1 trigger event can be done. conflicts may occur if both modules are using the same time base. capture pwm* none compare pwm* none pwm* capture none pwm* compare none pwm* pwm both pwms will have the same frequency and update rate (tmr2 interrupt). * includes standard and enhanced pwm operation.
? 2004 microchip technology inc. preliminary ds39625b-page 165 pic18f2585/2680/4585/4680 15.2 capture mode in capture mode, the eccpr1h:eccpr1l register pair captures the 16-bit value of the tmr1 or tmr3 registers when an event occurs on the ccp1 pin (rb3 or rc1, depending on device configuration). an event is defined as one of the following:  every falling edge  every rising edge  every 4th rising edge  every 16th rising edge the event is selected by the mode select bits, ccp1m3:ccp1m0 (ccp1con<3:0>). when a capture is made, the interrupt request flag bit, ccp1if (pir2<1>), is set; it must be cleared in software. if another capture occurs before the value in register ccpr1 is read, the old captured value is overwritten by the new captured value. 15.2.1 ccp1 pin configuration in capture mode, the appropriate ccp1 pin should be configured as an input by setting the corresponding tris direction bit. 15.2.2 timer1/timer3 mode selection the timers that are to be used with the capture feature (timer1 and/or timer3) must be running in timer mode or synchronized counter mode. in asynchronous counter mode, the capture operation may not work. the timer to be used with each ccp1 module is selected in the t3con register (see section 15.1.1 ?ccp1 modules and timer resources? ). 15.2.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep the ccp1ie or eccp1ie interrupt enable bit clear to avoid false interrupts. the interrupt flag bit, ccp1if or eccp1if, should also be cleared following any such change in operating mode. 15.2.4 ccp1 prescaler there are four prescaler settings in capture mode; they are specified as part of the operating mode selected by the mode select bits (ccp1m3:ccp1m0). whenever the ccp1 module is turned off or the ccp1 module is not in capture mode, the prescaler counter is cleared. this means that any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. also, the prescaler counter will not be cleared; therefore, the first capture may be from a non-zero prescaler. example 15-1 shows the recommended method for switching between capture prescalers. this example also clears the prescaler counter and will not generate the ?false? interrupt. 15.2.5 can message time-stamp the can capture event occurs when a message is received in any of the receive buffers. when config- ured, the can module provides the trigger to the ccp1 module to cause a capture event. this feature is provided to ?time-stamp? the received can messages. this feature is enabled by setting the cancap bit of the can i/o control register (ciocon<4>). the message receive signal from the can module then takes the place of the events on rc2/ccp1. if this feature is selected, then four different capture options for ccp1m<3:0> are available:  0100 ? every time a can message is received  0101 ? every time a can message is received  0110 ? every 4th time a can message is received  0111 ? capture mode, every 16th time a can message is received example 15-1: changing between capture prescalers note: if rc2/ccp1 or rd4/psp4/eccp1/p1a is configured as an output, a write to the port can cause a capture condition. clrf ccp1con ; turn ccp1 module off movlw new_capt_ps ; load wreg with the ; new prescaler mode ; value and ccp1 on movwf ccp1con ; load ccp1con with ; this value
pic18f2585/2680/4585/4680 ds39625b-page 166 preliminary ? 2004 microchip technology inc. figure 15-1: capture mode operat ion block diagram ccpr1h ccpr1l tmr1h tmr1l set ccp1if tmr3 enable q1:q4 ccp1con<3:0> ccp1 pin prescaler 1, 4, 16 and edge detect tmr1 enable t3eccp1 t3eccp1 eccpr1h eccpr1l tmr1h tmr1l set eccp1if tmr3 enable eccp1con<3:0> eccp1 pin prescaler 1, 4, 16 tmr3h tmr3l tmr1 enable t3eccp1 t3ccp1 t3eccp1 t3ccp1 tmr3h tmr3l and edge detect 4 4 4
? 2004 microchip technology inc. preliminary ds39625b-page 167 pic18f2585/2680/4585/4680 15.3 compare mode in compare mode, the 16-bit ccpr1 register value is constantly compared against either the tmr1 or tmr3 register pair value. when a match occurs, the ccp1 pin can be:  driven high  driven low  toggled (high-to-low or low-to-high)  remain unchanged (that is, reflects the state of the i/o latch) the action on the pin is based on the value of the mode select bits (eccp1m3:eccp1m0). at the same time, the interrupt flag bit eccp1if is set. 15.3.1 ccp1 pin configuration the user must configure the ccp1 (eccp1) pin as an output by clearing the appropriate tris bit. 15.3.2 timer1/timer3 mode selection timer1 and/or timer3 must be running in timer mode or synchronized counter mode if the ccp1 module is using the compare feature. in asynchronous counter mode, the compare operation may not work. 15.3.3 software interrupt mode when the generate software interrupt mode is chosen (ccp1m3:ccp1m0 = 1010 ), the ccp1 pin is not affected. only a ccp1 interrupt is generated, if enabled and the ccp1ie bit is set. 15.3.4 special event trigger both ccp1 modules are equipped with a special event trigger. this is an internal hardware signal generated in compare mode to trigger actions by other modules. the special event trigger is enabled by selecting the compare special event trigger mode (ccp1m3:ccp1m0 = 1011 ). for either ccp1 module, the special event trigger resets the timer register pair for whichever timer resource is currently assigned as the module?s time base. this allows the ccpr1 (eccpr1) registers to serve as a programmable period register for either timer. figure 15-2: compare mode operat ion block diagram note: clearing the ccp1con register will force the rc2 compare output latch (depending on device configuration) to the default low level. this is not the portc i/o data latch. ccpr1h ccpr1l tmr1h tmr1l comparator q s r output logic special event trigger set ccp1if ccp1 pin tris ccp1con<3:0> output enable tmr3h tmr3l eccpr1h eccpr1l comparator 1 0 t3eccp1 t3ccp1 set ccp1if 1 0 compare 4 (timer1 reset) q s r output logic special event trigger eccp1 pin tris eccp1con<3:0> output enable 4 (timer1/timer3 reset, a/d trigger) match compare match
pic18f2585/2680/4585/4680 ds39625b-page 168 preliminary ? 2004 microchip technology inc. table 15-3: registers associated with capture, compare, timer1 and timer3 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 rcon ipen sboren (3) ? ri to pd por bor 50 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr2 oscfip cmip (2) ? eeip bclip hlvdip tmr3ip eccp1ip (2) 51 pir2 oscfif cmif (2) ? eeif bclif hlvdif tmr3if eccp1if (2) 52 pie2 oscfie cmie (2) ? eeie bclie hlvdie tmr3ie eccp1ie (2) 51 trisb portb data direction register 52 trisc portc data direction register 52 tmr1l holding register for the least significant byte of the 16-bit tmr1 register 50 tmr1h holding register for the most significant byte of the 16-bit tmr1 register 50 t1con rd16 t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 50 tmr3h timer3 register high byte 51 tmr3l timer3 register low byte 51 t3con rd16 t3eccp1 (1) t3ckps1 t3ckps0 t3ccp1 t3sync tmr3cs tmr3on 51 ccpr1l capture/compare/pwm register 1 (lsb) 51 ccpr1h capture/compare/pwm register 1 (msb) 51 ccp1con ? ? dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 51 eccpr1l (1) enhanced capture/compare/pwm register 1 (lsb) 51 eccpr1h (1) enhanced capture/compare/pwm register 1 (msb) 51 eccp1con (1) epwm1m1 epwm1m0 edc1b1 edc1b0 eccp1m3 eccp1m2 eccp1m1 eccp1m0 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by capture and compare, timer1 or timer3. note 1: these bits or registers are available on pic18f4x8x devices only. 2: these bits are available on pic18f4x8x devices and reserved on pic18f2x8x devices. 3: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?.
? 2004 microchip technology inc. preliminary ds39625b-page 169 pic18f2585/2680/4585/4680 15.4 pwm mode in pulse-width modulation (pwm) mode, the ccp1 pin produces up to a 10-bit resolution pwm output. since the ccp1 pin is multiplexed with a portb or portc data latch, the appropriate tris bit must be cleared to make the ccp1 pin an output. figure 15-3 shows a simplified block diagram of the ccp1 module in pwm mode. for a step-by-step procedure on how to set up the ccp1 module for pwm operation, see section 15.4.4 ?setup for pwm operation? . figure 15-3: simplified pwm block diagram a pwm output (figure 15-4) has a time base (period) and a time that the output stays high (duty cycle). the frequency of the pwm is the inverse of the period (1/period). figure 15-4: pwm output 15.4.1 pwm period the pwm period is specified by writing to the pr2 (pr4) register. the pwm period can be calculated using the following formula. equation 15-1: pwm frequency is defined as 1/[pwm period]. when tmr1 (tmr3) is equal to pr2 (pr2), the following three events occur on the next increment cycle: tmr2 is cleared  the ccp1 pin is set (exception: if pwm duty cycle = 0%, the ccp1 pin will not be set)  the pwm duty cycle is latched from eccpr1l into eccpr1h 15.4.2 pwm duty cycle the pwm duty cycle is specified by writing to the eccpr1l register and to the ccp1con<5:4> bits. up to 10-bit resolution is available. the eccpr1l contains the eight msbs and the ccp1con<5:4> con- tains the two lsbs. this 10-bit value is represented by eccpr1l:eccp1con<5:4>. the following equation is used to calculate the pwm duty cycle in time. equation 15-2: eccpr1l and eccp1con<5:4> can be written to at any time, but the duty cycle value is not latched into eccpr1h until after a match between pr2 and tmr2 occurs (i.e., the period is complete). in pwm mode, eccpr1h is a read-only register. note: clearing the ccp1con register will force the rc2 output latch (depending on device configuration) to the default low level. this is not the portc i/o data latch. ccpr1l ccpr1h (slave) comparator tmr2 comparator pr2 (note 1) r q s duty cycle registers ccp1con<5:4> clear timer, ccp1 pin and latch d.c. trisc<2> rc2/ccp1 note 1: the 8-bit tmr2 value is concatenated with the 2-bit internal q clock, or 2 bits of the prescaler, to create the 10-bit time base. portc<2> note: the timer2 postscalers (see section 13.0 ?timer2 module? ) are not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a different frequency than the pwm output. period duty cycle tmr2 = pr2 tmr2 = duty cycle tmr2 = pr2 pwm period = (pr2) + 1]  4  t osc  (tmr2 prescale value) pwm duty cycle = (eccpr1l:eccp1con<5:4>)  t osc  (tmr2 prescale value)
pic18f2585/2680/4585/4680 ds39625b-page 170 preliminary ? 2004 microchip technology inc. the eccpr1h register and a 2-bit internal latch are used to double-buffer the pwm duty cycle. this double-buffering is essential for glitchless pwm operation. when the eccpr1h and 2-bit latch match tmr2, concatenated with an internal 2-bit q clock or 2 bits of the tmr2 prescaler, the ccp1 pin is cleared. the maximum pwm resolution (bits) for a given pwm frequency is given by the equation. equation 15-3: table 15-4: example pwm frequencies and resolutions at 40 mhz 15.4.3 pwm auto-shutdown (eccp1 only) the pwm auto-shutdown features of the enhanced ccp1 module are available to eccp1 in pic18f4585/4680 (40/44-pin) devices. the operation of this feature is discussed in detail in section 16.4.7 ?enhanced pwm auto-shutdown? . auto-shutdown features are not available for ccp1. 15.4.4 setup for pwm operation the following steps should be taken when configuring the ccp1 module for pwm operation: 1. set the pwm period by writing to the pr2 register. 2. set the pwm duty cycle by writing to the ccpr1l register and ccp1con<5:4> bits. 3. make the ccp1 pin an output by clearing the appropriate tris bit. 4. set the tmr2 prescale value, then enable timer2 by writing to t2con. 5. configure the ccp1 module for pwm operation. note: if the pwm duty cycle value is longer than the pwm period, the eccp1 pin will not be cleared. pwm resolution (max) = f osc f pwm log log(2) bits ? ? ? ? pwm frequency 2.44 khz 9.77 khz 39.06 khz 156.25 khz 312.50 khz 416.67 khz timer prescaler (1, 4, 16)1641111 pr2 value ffh ffh ffh 3fh 1fh 17h maximum resolution (bits) 14 12 10 8 7 6.58
? 2004 microchip technology inc. preliminary ds39625b-page 171 pic18f2585/2680/4585/4680 table 15-5: registers associated with pwm and timer2 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 rcon ipen sboren (2) ? ri to pd por bor 50 pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 trisb portb data direction register 52 trisc portc data direction register 52 tmr2 timer2 module register 50 pr2 timer2 module period register 50 t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 50 ccpr1l (1) capture/compare/pwm register 1 (lsb) 51 ccpr1h (1) capture/compare/pwm register 1 (msb) 51 ccp1con ? ? dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 51 eccpr1l (1) enhanced capture/compare/pwm register 1 (lsb) 51 eccpr1h (1) enhanced capture/compare/pwm register 1 (msb) 51 eccp1con (1) epwm1m1 epwm1m0 edc1b1 edc1b0 eccp1m3 eccp1m2 eccp1m1 eccp1m0 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by pwm or timer2. note 1: these registers are unimplemented on pic18f2x8x devices. 2: the sboren bit is only available when config2l<1:0> = 01 ; otherwise, it is disabled and reads as ? 0 ?.
pic18f2585/2680/4585/4680 ds39625b-page 172 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 173 pic18f2585/2680/4585/4680 16.0 enhanced capture/compare/pwm (eccp1) module in pic18f4585/4680 devices, eccp1 is implemented as a standard ccp1 module with enhanced pwm capabilities. these include the provision for 2 or 4 output channels, user selectable polarity, dead-band control and automatic shutdown and restart. the enhanced features are discussed in detail in section 16.4 ?enhanced pwm mode? . capture, compare and single output pwm functions of the eccp1 module are the same as described for the standard ccp1 module. the control register for the enhanced ccp1 module is shown in register 16-1. it differs from the ccp1con register in the pic18f2585/2680 devices in that the two most significant bits are implemented to control pwm functionality. register 16-1: eccp1con register (eccp1 module, pic18f4585/4680 devices) note: the eccp1 module is implemented only in pic18f4x8x (40/44-pin) devices. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 epwm1m1 epwm1m0 edc1b1 edc1b0 eccp1m3 eccp1m2 eccp1m1 eccp1m0 bit 7 bit 0 bit 7-6 epwm1m1:epwm1m0: enhanced pwm output configuration bits if e ccp1m3:eccp1m2 = 00 , 01 , 10 : xx = p1a assigned as capture/compare input/output; p1b, p1c, p1d assigned as port pins if eccp1m3:eccp1m2 = 11 : 00 = single output: p1a modulated; p1b, p1c, p1d assigned as port pins 01 = full-bridge output forward: p1d modulated; p1a active; p1b, p1c inactive 10 = half-bridge output: p1a, p1b modulated with dead-band control; p1c, p1d assigned as port pins 11 = full-bridge output reverse: p1b modulated; p1c active; p1a, p1d inactive bit 5-4 edc1b1:edc1b0 : pwm duty cycle bit 1 and bit 0 capture mode: unused. compare mode: unused. pwm mode: these bits are the two lsbs of the 10-bit pwm duty cycle. the eight msbs of the duty cycle are found in ccpr1l/eccpr1l. bit 3-0 eccp1m3:eccp1m0 : enhanced ccp1 mode select bits 0000 = capture/compare/pwm off (resets eccp1 module) 0001 = reserved 0010 = compare mode, toggle output on match 0011 = reserved 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, initialize eccp1 pin low, set output on compare match (set eccp1if) 1001 = compare mode, initialize eccp1 pin high, clear output on compare match (set eccp1if) 1010 = compare mode, generate software interrupt only, eccp1 pin reverts to i/o state 1011 = compare mode, trigger special event (eccp1 resets tmr1 or tmr3, sets eccp1if bit and starts the a/d conversion on eccp1 match) 1100 = pwm mode; p1a, p1c active-high; p1b, p1d active-high 1101 = pwm mode; p1a, p1c active-high; p1b, p1d active-low 1110 = pwm mode; p1a, p1c active-low; p1b, p1d active-high 1111 = pwm mode; p1a, p1c active-low; p1b, p1d active-low legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 174 preliminary ? 2004 microchip technology inc. in addition to the expanded range of modes available through the ccp1con register, the eccp1 module has two additional registers associated with enhanced pwm operation and auto-shutdown features. they are:  eccp1del (dead-band delay)  eccp1as (auto-shutdown configuration) 16.1 eccp1 outputs and configuration the enhanced ccp1 module may have up to four pwm outputs, depending on the selected operating mode. these outputs, designated p1a through p1d, are multiplexed with i/o pins on portc and portd. the outputs that are active depend on the ccp1 operating mode selected. the pin assignments are summarized in table 16-1. to configure the i/o pins as pwm outputs, the proper pwm mode must be selected by setting the epwm1m1:epwm1m0 and ccp1m3:ccp1m0 bits. the appropriate trisc and trisd direction bits for the port pins must also be set as outputs. 16.1.1 eccp1 modules and timer resources like the standard ccp1 modules, the eccp1 module can utilize timers 1, 2 or 3, depending on the mode selected. timer1 and timer3 are available for modules in capture or compare modes, while timer2 is available for modules in pwm mode. interactions between the standard and enhanced ccp1 modules are identical to those described for standard ccp1 modules. additional details on timer resources are provided in section 15.1.1 ?ccp1 modules and timer resources? . 16.2 capture and compare modes except for the operation of the special event trigger discussed below, the capture and compare modes of the eccp1 module are identical in operation to that of ccp1. these are discussed in detail in section 15.2 ?capture mode? and section 15.3 ?compare mode? . 16.2.1 special event trigger the special event trigger output of eccp1 resets the tmr1 or tmr3 register pair, depending on which timer resource is currently selected. this allows the eccp1 register to effectively be a 16-bit programmable period register for timer1 or timer3. the special event trigger for eccp1 can also start an a/d conversion. in order to start the conversion, the a/d converter must be previously enabled. 16.3 standard pwm mode when configured in single output mode, the eccp1 module functions identically to the standard ccp1 module in pwm mode, as described in section 15.4 ?pwm mode? . this is also sometimes referred to as ?compatible ccp1? mode, as in table 16-1. table 16-1: pin assignments for various eccp1 modes note: when setting up single output pwm operations, users are free to use either of the processes described in section 15.4.4 ?setup for pwm operation? or section 16.4.9 ?setup for pwm operation? . the latter is more generic but will work for either single or multi-output pwm. eccp1 mode ccp1con configuration rd4 rd5 rd6 rd7 all pic18f4585/4680 devices: compatible ccp1 00xx 11xx ccp1 rd5/psp5 rd6/psp6 rd7/psp7 dual pwm 10xx 11xx p1a p1b rd6/psp6 rd7/psp7 quad pwm x1xx 11xx p1a p1b p1c p1d legend: x = don?t care. shaded cells indicate pin assignments not used by eccp1 in a given mode.
? 2004 microchip technology inc. preliminary ds39625b-page 175 pic18f2585/2680/4585/4680 16.4 enhanced pwm mode the enhanced pwm mode provides additional pwm output options for a broader range of control applica- tions. the module is a backward compatible version of the standard ccp1 module and offers up to four out- puts, designated p1a through p1d. users are also able to select the polarity of the signal (either active-high or active-low). the module?s output mode and polarity are configured by setting the epwm1m1:epwm1m0 and ccp1m3:ccp1m0 bits of the eccp1con register. figure 16-1 shows a simplified block diagram of pwm operation. all control registers are double-buffered and are loaded at the beginning of a new pwm cycle (the period boundary when timer2 resets) in order to prevent glitches on any of the outputs. the exception is the pwm delay register, eccp1del, which is loaded at either the duty cycle boundary or the boundary period (whichever comes first). because of the buffer- ing, the module waits until the assigned timer resets instead of starting immediately. this means that enhanced pwm waveforms do not exactly match the standard pwm waveforms but are instead offset by one full instruction cycle (4 t osc ). as before, the user must manually configure the appropriate tris bits for output. 16.4.1 pwm period the pwm period is specified by writing to the pr2 register. the pwm period can be calculated using the following equation. equation 16-1: pwm frequency is defined as 1/[pwm period]. when tmr2 is equal to pr2, the following three events occur on the next increment cycle: tmr2 is cleared  the eccp1 pin is set (if pwm duty cycle = 0%, the eccp1 pin will not be set)  the pwm duty cycle is copied from eccpr1l into eccpr1h figure 16-1: simplified block diagram of the enhanced pwm module note: the timer2 postscaler (see section 13.0 ?timer2 module? ) is not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a different frequency than the pwm output. pwm period = [(pr2) + 1]  4  t osc  (tmr2 prescale value) eccpr1l eccpr1h (slave) comparator tmr2 comparator pr2 (note 1) rq s duty cycle registers ccp1con<5:4> clear timer, set eccp1 pin and latch d.c. note: the 8-bit tmr2 register is concatenated with the 2-bit internal q clock, or 2 bits of the prescaler, to create the 10-bit time base. trisd<4> eccp1/p1a trisd<5> p1b trisd<6> trisd<7> p1d output controller epwm1m1<1:0> 2 ccp1m<3:0> 4 eccp1del eccp1/p1a p1b p1c p1d p1c
pic18f2585/2680/4585/4680 ds39625b-page 176 preliminary ? 2004 microchip technology inc. 16.4.2 pwm duty cycle the pwm duty cycle is specified by writing to the eccpr1l register and to the eccp1con<5:4> bits. up to 10-bit resolution is available. the eccpr1l contains the eight msbs and the eccp1con<5:4> contains the two lsbs. this 10-bit value is represented by eccpr1l:eccp1con<5:4>. the pwm duty cycle is calculated by the following equation. equation 16-2: eccpr1l and eccp1con<5:4> can be written to at any time, but the duty cycle value is not copied into eccpr1h until a match between pr2 and tmr2 occurs (i.e., the period is complete). in pwm mode, eccpr1h is a read-only register. the eccpr1h register and a 2-bit internal latch are used to double-buffer the pwm duty cycle. this double-buffering is essential for glitchless pwm opera- tion. when the eccpr1h and 2-bit latch match tmr2, concatenated with an internal 2-bit q clock or two bits of the tmr2 prescaler, the eccp1 pin is cleared. the maximum pwm resolution (bits) for a given pwm frequency is given by the following equation. equation 16-3: 16.4.3 pwm output configurations the epwm1m1:epwm1m0 bits in the eccp1con register allow one of four configurations:  single output  half-bridge output  full-bridge output, forward mode  full-bridge output, reverse mode the single output mode is the standard pwm mode discussed in section 16.4 ?enhanced pwm mode? . the half-bridge and full-bridge output modes are covered in detail in the sections that follow. the general relationship of the outputs in all configurations is summarized in figure 16-2. table 16-2: example pwm frequencies and resolutions at 40 mhz pwm duty cycle = (eccpr1l:eccp1con<5:4>  t osc  (tmr2 prescale value) note: if the pwm duty cycle value is longer than the pwm period, the ccp1 pin will not be cleared. ( ) pwm resolution (max) = f osc f pwm log log(2) bits pwm frequency 2.44 khz 9.77 khz 39.06 khz 156.25 khz 312.50 khz 416.67 khz timer prescaler (1, 4, 16)1641111 pr2 value ffh ffh ffh 3fh 1fh 17h maximum resolution (bits) 10 10 10 8 7 6.58
? 2004 microchip technology inc. preliminary ds39625b-page 177 pic18f2585/2680/4585/4680 figure 16-2: pwm output relationships (active-high state) figure 16-3: pwm output relationships (active-low state) 0 period 00 10 01 11 signal pr2 + 1 eccp1con <7:6> p1a modulated p1a modulated p1b modulated p1a active p1b inactive p1c inactive p1d modulated p1a inactive p1b modulated p1c active p1d inactive duty cycle (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) 0 period 00 10 01 11 signal pr2 + 1 eccp1con <7:6> p1a modulated p1a modulated p1b modulated p1a active p1b inactive p1c inactive p1d modulated p1a inactive p1b modulated p1c active p1d inactive duty cycle (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) relationships:  period = 4 * t osc * (pr2 + 1) * (tmr2 prescale value)  duty cycle = t osc * (eccpr1l<7:0>:eccp1con<5:4>) * (tmr2 prescale value)  delay = 4 * t osc * (eccp1del<6:0>) note1: dead-band delay is programmed us ing the eccp1del register ( section 16.4.6 ?programmable dead-band delay? ).
pic18f2585/2680/4585/4680 ds39625b-page 178 preliminary ? 2004 microchip technology inc. 16.4.4 half-bridge mode in the half-bridge output mode, two pins are used as outputs to drive push-pull loads. the pwm output signal is output on the p1a pin, while the complemen- tary pwm output signal is output on the p1b pin (figure 16-4). this mode can be used for half-bridge applications, as shown in figure 16-5, or for full-bridge applications where four power switches are being modulated with two pwm signals. in half-bridge output mode, the programmable dead-band delay can be used to prevent shoot-through current in half-bridge power devices. the value of bits, pdc6:pdc0, sets the number of instruction cycles before the output is driven active. if the value is greater than the duty cycle, the corresponding output remains inactive during the entire cycle. see section 16.4.6 ?programmable dead-band delay? for more details of the dead-band delay operations. since the p1a and p1b outputs are multiplexed with the portd<4> and portd<5> data latches, the trisd<4> and trisd<5> bits must be cleared to configure p1a and p1b as outputs. figure 16-4: half-bridge pwm output figure 16-5: examples of half-bri dge output mode applications period duty cycle td td (1) p1a (2) p1b (2) td = dead-band delay period (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: output signals are shown as active-high. pic18fx585/x680 p1a p1b fet driver fet driver v+ v- load + v - + v - fet driver fet driver v+ v- load fet driver fet driver pic18fx585/x680 p1a p1b standard half-bridge circuit (?push-pull?) half-bridge output driving a full-bridge circuit
? 2004 microchip technology inc. preliminary ds39625b-page 179 pic18f2585/2680/4585/4680 16.4.5 full-bridge mode in full-bridge output mode, four pins are used as outputs; however, only two outputs are active at a time. in the forward mode, pin p1a is continuously active and pin p1d is modulated. in the reverse mode, pin p1c is continuously active and pin p1b is modulated. these are illustrated in figure 16-6. p1a, p1b, p1c and p1d outputs are multiplexed with the portd<4>, portd<5>, portd<6> and portd<7> data latches. the trisd<4>, trisd<5>, trisd<6> and trisd<7> bits must be cleared to make the p1a, p1b, p1c and p1d pins outputs. figure 16-6: full-bridge pwm output period duty cycle p1a (2) p1b (2) p1c (2) p1d (2) forward mode (1) period duty cycle p1a (2) p1c (2) p1d (2) p1b (2) reverse mode (1) (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. note 2: output signal is shown as active-high.
pic18f2585/2680/4585/4680 ds39625b-page 180 preliminary ? 2004 microchip technology inc. figure 16-7: example of full-bridge application 16.4.5.1 direction change in full-bridge mode in the full-bridge output mode, the epwm1m1 bit in the ccp1con register allows the user to control the forward/reverse direction. when the application firmware changes this direction control bit, the module will assume the new direction on the next pwm cycle. just before the end of the current pwm period, the modulated outputs (p1b and p1d) are placed in their inactive state, while the unmodulated outputs (p1a and p1c) are switched to drive in the opposite direction. this occurs in a time interval of (4 t osc * (timer2 prescale value)) before the next pwm period begins. the timer2 prescaler will be either 1, 4 or 16, depend- ing on the value of the t2ckps bit (t2con<1:0>). during the interval from the switch of the unmodulated outputs to the beginning of the next period, the modulated outputs (p1b and p1d) remain inactive. this relationship is shown in figure 16-8. note that in the full-bridge output mode, the ccp1 module does not provide any dead-band delay. in general, since only one output is modulated at all times, dead-band delay is not required. however, there is a situation where a dead-band delay might be required. this situation occurs when both of the following conditions are true: 1. the direction of the pwm output changes when the duty cycle of the output is at or near 100%. 2. the turn-off time of the power switch, including the power device and driver circuit, is greater than the turn-on time. figure 16-9 shows an example where the pwm direc- tion changes from forward to reverse at a near 100% duty cycle. at time t1, the outputs p1a and p1d become inactive, while output p1c becomes active. in this example, since the turn-off time of the power devices is longer than the turn-on time, a shoot-through current may flow through power devices, qc and qd (see figure 16-7), for the duration of ?t?. the same phenomenon will occur to power devices, qa and qb, for pwm direction change from reverse to forward. if changing pwm direction at high duty cycle is required for an application, one of the following requirements must be met: 1. reduce pwm for a pwm period before changing directions. 2. use switch drivers that can drive the switches off faster than they can drive them on. other options to prevent shoot-through current may exist. p1a p1c fet driver fet driver v+ v- load fet driver fet driver p1b p1d qa qb qd qc pic18fx585/x680
? 2004 microchip technology inc. preliminary ds39625b-page 181 pic18f2585/2680/4585/4680 figure 16-8: pwm direction change figure 16-9: pwm direction chang e at near 100% duty cycle dc period (1) signal note 1: the direction bit in the ccp1 control register (ccp 1con<7>) is written any time during the pwm cycle. 2: when changing directions, the p1a and p1c signals switch before the end of the current pwm cycle at intervals of 4 t osc , 16 t osc or 64 t osc , depending on the timer2 prescaler value. the modulated p1b and p1d signals are inactive at this time. period (note 2) p1a (active-high) p1b (active-high) p1c (active-high) p1d (active-high) dc forward period reverse period p1a (1) t on (2) t off (3) t = t off ? t on (2,3) p1b (1) p1c (1) p1d (1) external switch d (1) potential shoot-through current (1) note 1: all signals are shown as active-high. 2: t on is the turn-on delay of power switch qc and its driver. 3: t off is the turn-off delay of power switch qd and its driver. external switch c (1) t1 dc dc
pic18f2585/2680/4585/4680 ds39625b-page 182 preliminary ? 2004 microchip technology inc. 16.4.6 programmable dead-band delay in half-bridge applications where all power switches are modulated at the pwm frequency at all times, the power switches normally require more time to turn off than to turn on. if both the upper and lower power switches are switched at the same time (one turned on and the other turned off), both switches may be on for a short period of time until one switch completely turns off. during this brief interval, a very high current ( shoot-through current ) may flow through both power switches, shorting the bridge supply. to avoid this potentially destructive shoot-through current from flowing during switching, turning on either of the power switches is normally delayed to allow the other switch to completely turn off. in the half-bridge output mode, a digitally program- mable dead-band delay is available to avoid shoot-through current from destroying the bridge power switches. the delay occurs at the signal transi- tion from the non-active state to the active state. see figure 16-4 for illustration. bits pdc6:pdc0 of the eccp1del register (register 16-2) set the delay period in terms of microcontroller instruction cycles (t cy or 4 t osc ). these bits are not available on pic18f2x8x devices, as the standard ccp1 module does not support half-bridge operation. 16.4.7 enhanced pwm auto-shutdown when the ccp1 is programmed for any of the enhanced pwm modes, the active output pins may be configured for auto-shutdown. auto-shutdown immediately places the enhanced pwm output pins into a defined shutdown state when a shutdown event occurs. a shutdown event can be caused by either of the comparator modules, a low level on the rb0/int0/flt0/an10 pin, or any combination of these three sources. the comparators may be used to monitor a voltage input proportional to a current being monitored in the bridge circuit. if the voltage exceeds a threshold, the comparator switches state and triggers a shutdown. alternatively, a digital signal on the int0 pin can also trigger a shutdown. the auto-shutdown feature can be disabled by not selecting any auto-shutdown sources. the auto-shutdown sources to be used are selected using the eccpas2:eccpas0 bits (bits<6:4> of the eccp1as register). when a shutdown occurs, the output pins are asyn- chronously placed in their shutdown states, specified by the pssac1:pssac0 and pss1bd1:pss1bd0 bits (eccpas3:eccpas0). each pin pair (p1a/p1c and p1b/p1d) may be set to drive high, drive low or be tri-stated (not driving). the eccpase bit (eccp1as<7>) is also set to hold the enhanced pwm outputs in their shutdown states. the eccpase bit is set by hardware when a shutdown event occurs. if automatic restarts are not enabled, the eccpase bit is cleared by firmware when the cause of the shutdown clears. if automatic restarts are enabled, the eccpase bit is automatically cleared when the cause of the auto-shutdown has cleared. if the eccpase bit is set when a pwm period begins, the pwm outputs remain in their shutdown state for that entire pwm period. when the eccpase bit is cleared, the pwm outputs will return to normal operation at the beginning of the next pwm period. register 16-2: eccp1del: pwm configuratio n register note: programmable dead-band delay is not implemented in pic18f2x8x devices with standard ccp1 modules. note: writing to the eccpase bit is disabled while a shutdown condition is active. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 prsen pdc6 (1) pdc5 (1) pdc4 (1) pdc3 (1) pdc2 (1) pdc1 (1) pdc0 (1) bit 7 bit 0 bit 7 prsen: pwm restart enable bit 1 = upon auto-shutdown, the eccpase bit clears automatically once the shutdown event goes away; the pwm restarts automatically 0 = upon auto-shutdown, eccpase must be cleared in software to restart the pwm bit 6-0 pdc6:pdc0: pwm delay count bits (1) delay time, in number of f osc /4 (4 * t osc ) cycles, between the scheduled and actual time for a pwm signal to transition to active. note 1: reserved on pic18f2x8x devices; maintain these bits clear. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 183 pic18f2585/2680/4585/4680 register 16-3: eccp1as: enhanced capture/compare/pwm auto-shutdown control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eccpase eccpas2 eccpas1 eccpas0 pssac1 pssac0 pssbd1 (1) pssbd0 (1) bit 7 bit 0 bit 7 eccpase: eccp1 auto-shutdown event status bit 1 = a shutdown event has occurred; eccp1 outputs are in shutdown state 0 = eccp1 outputs are operating bit 6-4 eccpas2:eccpas0: eccp1 auto-shutdown source select bits 111 = rb0 or comparator 1 or comparator 2 110 = rb0 or comparator 2 101 = rb0 or comparator 1 100 = rb0 011 = either comparator 1 or 2 010 = comparator 2 output 001 = comparator 1 output 000 = auto-shutdown is disabled bit 3-2 pssac1:pssac0: pins a and c shutdown state control bits 1x = pins a and c tri-state (pic18f4x8x devices); 01 = drive pins a and c to ? 1 ? 00 = drive pins a and c to ? 0 ? bit 1-0 pssbd1:pssbd0: pins b and d shutdown state control bits (1) 1x = pins b and d tri-state 01 = drive pins b and d to ? 1 ? 00 = drive pins b and d to ? 0 ? note 1: reserved on pic18f2x8x devices; maintain these bits clear. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 184 preliminary ? 2004 microchip technology inc. 16.4.7.1 auto-shutdown and auto-restart the auto-shutdown feature can be configured to allow automatic restarts of the module following a shutdown event. this is enabled by setting the prsen bit of the eccp1del register (eccp1del<7>). in shutdown mode with prsen = 1 (figure 16-10), the eccpase bit will remain set for as long as the cause of the shutdown continues. when the shutdown condi- tion clears, the eccp1ase bit is cleared. if prsen = 0 (figure 16-11), once a shutdown condition occurs, the eccpase bit will remain set until it is cleared by firmware. once eccpase is cleared, the enhanced pwm will resume at the beginning of the next pwm period. independent of the prsen bit setting, if the auto-shutdown source is one of the comparators, the shutdown condition is a level. the eccpase bit cannot be cleared as long as the cause of the shutdown persists. the auto-shutdown mode can be forced by writing a ? 1 ? to the eccpase bit. 16.4.8 start-up considerations when the eccp1 module is used in the pwm mode, the application hardware must use the proper external pull-up and/or pull-down resistors on the pwm output pins. when the microcontroller is released from reset, all of the i/o pins are in the high-impedance state. the external circuits must keep the power switch devices in the off state until the microcontroller drives the i/o pins with the proper signal levels, or activates the pwm output(s). the eccp1m1:eccp1m0 bits (eccp1con<1:0>) allow the user to choose whether the pwm output sig- nals are active-high or active-low for each pair of pwm output pins (p1a/p1c and p1b/p1d). the pwm output polarities must be selected before the pwm pins are configured as outputs. changing the polarity configura- tion while the pwm pins are configured as outputs is not recommended, since it may result in damage to the application circuits. the p1a, p1b, p1c and p1d output latches may not be in the proper states when the pwm module is initialized. enabling the pwm pins for output at the same time as the eccp1 module may cause damage to the applica- tion circuit. the eccp1 module must be enabled in the proper output mode and complete a full pwm cycle before configuring the pwm pins as outputs. the com- pletion of a full pwm cycle is indicated by the tmr2if bit being set as the second pwm period begins. figure 16-10: pwm auto-shutdown (prsen = 1 , auto-restart enabled) figure 16-11: pwm auto-shutdown (prsen = 0 , auto-restart disabled) note: writing to the eccpase bit is disabled while a shutdown condition is active. shutdown pwm eccpase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period pwm period shutdown pwm eccpase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period eccpase cleared by firmware pwm period
? 2004 microchip technology inc. preliminary ds39625b-page 185 pic18f2585/2680/4585/4680 16.4.9 setup for pwm operation the following steps should be taken when configuring the eccp1 module for pwm operation: 1. configure the pwm pins p1a and p1b (and p1c and p1d, if used) as inputs by setting the corresponding tris bits. 2. set the pwm period by loading the pr2 register. 3. configure the eccp1 module for the desired pwm mode and configuration by loading the eccp1con register with the appropriate values:  select one of the available output configurations and direction with the epwm1m1:epwm1m0 bits.  select the polarities of the pwm output signals with the eccp1m3:eccp1m0 bits. 4. set the pwm duty cycle by loading the eccpr1l register and eccp1con<5:4> bits. 5. for half-bridge output mode, set the dead-band delay by loading eccp1del<6:0> with the appropriate value. 6. if auto-shutdown operation is required, load the eccp1as register:  select the auto-shutdown sources using the eccpas2:eccpas0 bits.  select the shutdown states of the pwm output pins using pssac1:pssac0 and pssbd1:pssbd0 bits.  set the eccpase bit (eccp1as<7>).  configure the comparators using the cmcon register.  configure the comparator inputs as analog inputs. 7. if auto-restart operation is required, set the prsen bit (eccp1del<7>). 8. configure and start tmr2:  clear the tmr2 interrupt flag bit by clearing the tmr2if bit (pir1<1>).  set the tmr2 prescale value by loading the t2ckps bits (t2con<1:0>).  enable timer2 by setting the tmr2on bit (t2con<2>). 9. enable pwm outputs after a new pwm cycle has started:  wait until tmrn overflows (tmrnif bit is set).  enable the eccp1/p1a, p1b, p1c and/or p1d pin outputs by clearing the respective tris bits.  clear the eccpase bit (eccp1as<7>). 16.4.10 effects of a reset both power-on reset and subsequent resets will force all ports to input mode and the ccp1 registers to their reset states. this forces the enhanced ccp1 module to reset to a state compatible with the standard ccp1 module.
pic18f2585/2680/4585/4680 ds39625b-page 186 preliminary ? 2004 microchip technology inc. table 16-3: registers associated with eccp1 module and timer1 to timer3 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 rcon ipen sboren ? ri to pd por bor 50 ipr1 pspip adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 pir1 pspif adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr2 oscfip cmip (3) ? eeip bclip hlvdip tmr3ip eccp1ip (3) 51 pir2 oscfif cmif (3) ? eeif bclif hlvdif tmr3if eccp1if (3) 51 pie2 oscfie cmie (3) ? eeie bclie hlvdie tmr3ie eccp1ie (3) 52 trisb portb data direction register 52 trisc portc data direction register 52 trisd (1) portd data direction register 52 tmr1l holding register for the least significant byte of the 16-bit tmr1 register 50 tmr1h holding register for the most significant byte of the 16-bit tmr1 register 50 t1con rd16 t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 50 tmr2 timer2 module register 50 t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 50 pr2 timer2 period register 50 tmr3l holding register for the least significant byte of the 16-bit tmr3 register 51 tmr3h holding register for the most significant byte of the 16-bit tmr3 register 51 t3con rd16 t3eccp1 (1) t3ckps1 t3ckps0 t3ccp1 (1) t3sync tmr3cs tmr3on 51 eccpr1l (2) enhanced capture/compare/pwm register 1 (lsb) 51 eccpr1h (2) enhanced capture/compare/pwm register 1 (msb) 51 eccp1con (2) epwm1m1 epwm1m0 edc1b1 edc1b0 eccp1m3 eccp1m2 eccp1m1 eccp1m0 51 eccp1as (2) eccpase eccpas2 eccpas1 eccpas0 pssac1 pssac0 pssbd1 (2) pssbd0 (2) 51 eccp1del (2) prsen pdc6 (2) pdc5 (2) pdc4 (2) pdc3 (2) pdc2 (2) pdc1 (2) pdc0 (2) 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used during eccp1 operation. note 1: these bits are available on pic18f4x8x devices only. 2: these bits or registers are unimplemented in pic18f2x8x devices; always maintain these bit clear. 3: these bits are available on pic18f4x8x and reserved on pic18f2x8x devices.
? 2004 microchip technology inc. preliminary ds39625b-page 187 pic18f2585/2680/4585/4680 17.0 master synchronous serial port (mssp) module 17.1 master ssp (mssp) module overview the master synchronous serial port (mssp) module is a serial interface, useful for communicating with other peripheral or microcontroller devices. these peripheral devices may be serial eeproms, shift registers, display drivers, a/d converters, etc. the mssp module can operate in one of two modes:  serial peripheral interface (spi)  inter-integrated circuit (i 2 c) - full master mode - slave mode (with general address call) the i 2 c interface supports the following modes in hardware: master mode  multi-master mode  slave mode 17.2 control registers the mssp module has three associated registers. these include a status register (sspstat) and two control registers (sspcon1 and sspcon2). the use of these registers and their individual configuration bits differ significantly depending on whether the mssp module is operated in spi or i 2 c mode. additional details are provided under the individual sections. 17.3 spi mode the spi mode allows 8 bits of data to be synchronously transmitted and received simultaneously. all four modes of spi are supported. to accomplish communication, typically three pins are used:  serial data out (sdo) ? rc5/sdo  serial data in (sdi) ? rc4/sdi/sda  serial clock (sck) ? rc3/sck/scl additionally, a fourth pin may be used when in a slave mode of operation:  slave select (ss ) ? ra5/an4/ss /hlvdin figure 17-1 shows the block diagram of the mssp module when operating in spi mode. figure 17-1: mssp block diagram (spi? mode) ( ) read write internal data bus sspsr reg sspm3:sspm0 bit 0 shift clock ss control enable edge select clock select tmr2 output t osc prescaler 4, 16, 64 2 edge select 2 4 data to tx/rx in sspsr tris bit 2 smp:cke rc5/sdo sspbuf reg rc4/sdi/sda ra5/an4/ss /hlvdin rc3/sck/scl
pic18f2585/2680/4585/4680 ds39625b-page 188 preliminary ? 2004 microchip technology inc. 17.3.1 registers the mssp module has four registers for spi mode operation. these are:  mssp control register 1 (sspcon1)  mssp status register (sspstat)  serial receive/transmit buffer register (sspbuf)  mssp shift register (sspsr) ? not directly accessible sspcon1 and sspstat are the control and status registers in spi mode operation. the sspcon1 register is readable and writable. the lower 6 bits of the sspstat are read-only. the upper two bits of the sspstat are read/write. sspsr is the shift register used for shifting data in or out. sspbuf is the buffer register to which data bytes are written to or read from. in receive operations, sspsr and sspbuf together create a double-buffered receiver. when sspsr receives a complete byte, it is transferred to sspbuf and the sspif interrupt is set. during transmission, the sspbuf is not double- buffered. a write to sspbuf will write to both sspbuf and sspsr. register 17-1: sspstat: mssp status register (spi mode) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a psr/w ua bf bit 7 bit 0 bit 7 smp: sample bit spi master mode: 1 = input data sampled at end of data output time 0 = input data sampled at middle of data output time spi slave mode: smp must be cleared when spi is used in slave mode. bit 6 cke: spi clock select bit 1 = transmit occurs on transition from active to idle clock state 0 = transmit occurs on transition from idle to active clock state polarity of clock state is set by the ckp bit (sspcon1<4>). bit 5 d/a : data/address bit used in i 2 c mode only. bit 4 p: stop bit used in i 2 c mode only. this bit is cleared when the mssp module is disabled, sspen is cleared. bit 3 s: start bit used in i 2 c mode only. bit 2 r/w : read/write bit information used in i 2 c mode only. bit 1 ua: update address bit used in i 2 c mode only. bit 0 bf: buffer full status bit (receive mode only) 1 = receive complete, sspbuf is full 0 = receive not complete, sspbuf is empty legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 189 pic18f2585/2680/4585/4680 register 17-2: sspcon1: mssp control register 1 (spi mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 bit 7 bit 0 bit 7 wcol: write collision detect bit (transmit mode only) 1 = the sspbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision bit 6 sspov: receive overflow indicator bit spi slave mode: 1 = a new byte is received while the sspbuf register is still holding the previous data. in case of overflow, the data in sspsr is lost. overflow can only occur in slave mode. the user must read the sspbuf, even if only transmitting data, to avoid setting overflow (must be cleared in software). 0 = no overflow note: in master mode, the overflow bit is not set since each new reception (and transmission) is initiated by writing to the sspbuf register. bit 5 sspen: synchronous serial port enable bit 1 = enables serial port and configures sck, sdo, sdi and ss as serial port pins 0 = disables serial port and configures these pins as i/o port pins note: when enabled, these pins must be properly configured as input or output. bit 4 ckp: clock polarity select bit 1 = idle state for clock is a high level 0 = idle state for clock is a low level bit 3-0 sspm3:sspm0: synchronous serial port mode select bits 0101 = spi slave mode, clock = sck pin, ss pin control disabled, ss can be used as i/o pin 0100 = spi slave mode, clock = sck pin, ss pin control enabled 0011 = spi master mode, clock = tmr2 output/2 0010 = spi master mode, clock = f osc /64 0001 = spi master mode, clock = f osc /16 0000 = spi master mode, clock = f osc /4 note: bit combinations not specifically listed here are either reserved or implemented in i 2 c mode only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 190 preliminary ? 2004 microchip technology inc. 17.3.2 operation when initializing the spi, several options need to be specified. this is done by programming the appropriate control bits (sspcon1<5:0> and sspstat<7:6>). these control bits allow the following to be specified:  master mode (sck is the clock output)  slave mode (sck is the clock input)  clock polarity (idle state of sck)  data input sample phase (middle or end of data output time)  clock edge (output data on rising/falling edge of sck)  clock rate (master mode only)  slave select mode (slave mode only) the mssp consists of a transmit/receive shift register (sspsr) and a buffer register (sspbuf). the sspsr shifts the data in and out of the device, msb first. the sspbuf holds the data that was written to the sspsr until the received data is ready. once the 8 bits of data have been received, that byte is moved to the sspbuf register. then, the buffer full detect bit, bf (sspstat<0>) and the interrupt flag bit, sspif, are set. this double-buffering of the received data (sspbuf) allows the next byte to start reception before reading the data that was just received. any write to the sspbuf register during transmission/reception of data will be ignored and the write collision detect bit, wcol (sspcon1<7>), will be set. user software must clear the wcol bit so that it can be determined if the follow- ing write(s) to the sspbuf register completed successfully. when the application software is expecting to receive valid data, the sspbuf should be read before the next byte of data to transfer is written to the sspbuf. the buffer full bit, bf (sspstat<0>), indicates when sspbuf has been loaded with the received data (transmission is complete). when the sspbuf is read, the bf bit is cleared. this data may be irrelevant if the spi is only a transmitter. generally, the mssp interrupt is used to determine when the transmission/reception has completed. the sspbuf must be read and/or written. if the interrupt method is not going to be used, then software polling can be done to ensure that a write collision does not occur. example 17-1 shows the loading of the sspbuf (sspsr) for data transmission. the sspsr is not directly readable or writable and can only be accessed by addressing the sspbuf register. additionally, the mssp status register (sspstat) indicates the various status conditions. example 17-1: loading the sspbuf (sspsr) register loop btfss sspstat, bf ;has data been received (transmit complete)? bra loop ;no movf sspbuf, w ;wreg reg = contents of sspbuf movwf rxdata ;save in user ram, if data is meaningful movf txdata, w ;w reg = contents of txdata movwf sspbuf ;new data to xmit
? 2004 microchip technology inc. preliminary ds39625b-page 191 pic18f2585/2680/4585/4680 17.3.3 enabling spi i/o to enable the serial port, ssp enable bit, sspen (sspcon1<5>), must be set. to reset or reconfigure spi mode, clear the sspen bit, reinitialize the sspcon registers and then set the sspen bit. this configures the sdi, sdo, sck and ss pins as serial port pins. for the pins to behave as the serial port function, some must have their data direction bits (in the tris register) appropriately programmed as follows:  sdi is automatically controlled by the spi module  sdo must have trisc<5> bit cleared  sck (master mode) must have trisc<3> bit cleared  sck (slave mode) must have trisc<3> bit set ss must have trisf<7> bit set any serial port function that is not desired may be overridden by programming the corresponding data direction (tris) register to the opposite value. 17.3.4 typical connection figure 17-2 shows a typical connection between two microcontrollers. the master controller (processor 1) initiates the data transfer by sending the sck signal. data is shifted out of both shift registers on their programmed clock edge and latched on the opposite edge of the clock. both processors should be programmed to the same clock polarity (ckp), then both controllers would send and receive data at the same time. whether the data is meaningful (or dummy data) depends on the application software. this leads to three scenarios for data transmission:  master sends data ? slave sends dummy data  master sends data ? slave sends data  master sends dummy data ? slave sends data figure 17-2: spi? master/slave connection serial input buffer (sspbuf) shift register (sspsr) msb lsb sdo sdi processor 1 sck spi? master sspm3:sspm0 = 00xxb serial input buffer (sspbuf) shift register (sspsr) lsb msb sdi sdo processor 2 sck spi? slave sspm3:sspm0 = 010xb serial clock
pic18f2585/2680/4585/4680 ds39625b-page 192 preliminary ? 2004 microchip technology inc. 17.3.5 master mode the master can initiate the data transfer at any time because it controls the sck. the master determines when the slave (processor 2, figure 17-2) is to broadcast data by the software protocol. in master mode, the data is transmitted/received as soon as the sspbuf register is written to. if the spi is only going to receive, the sdo output could be disabled (programmed as an input). the sspsr regis- ter will continue to shift in the signal present on the sdi pin at the programmed clock rate. as each byte is received, it will be loaded into the sspbuf register as if a normal received byte (interrupts and status bits appropriately set). this could be useful in receiver applications as a ?line activity monitor? mode. the clock polarity is selected by appropriately programming the ckp bit (sspcon1<4>). this then, would give waveforms for spi communication as shown in figure 17-3, figure 17-5 and figure 17-6, where the msb is transmitted first. in master mode, the spi clock rate (bit rate) is user-programmable to be one of the following: f osc /4 (or t cy ) f osc /16 (or 4  t cy ) f osc /64 (or 16  t cy )  timer2 output/2 this allows a maximum data rate (at 40 mhz) of 10.00 mbps. figure 17-3 shows the waveforms for master mode. when the cke bit is set, the sdo data is valid before there is a clock edge on sck. the change of the input sample is shown based on the state of the smp bit. the time when the sspbuf is loaded with the received data is shown. figure 17-3: spi? mode waveform (master mode) sck (ckp = 0 sck (ckp = 1 sck (ckp = 0 sck (ckp = 1 4 clock modes input sample input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 sdi sspif (smp = 1 ) (smp = 0 ) (smp = 1 ) cke = 1 ) cke = 0 ) cke = 1 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 (cke = 0 ) (cke = 1 ) next q4 cycle after q2 bit 0
? 2004 microchip technology inc. preliminary ds39625b-page 193 pic18f2585/2680/4585/4680 17.3.6 slave mode in slave mode, the data is transmitted and received as the external clock pulses appear on sck. when the last bit is latched, the sspif interrupt flag bit is set. before enabling the module in spi slave mode, the clock line must match the proper idle state. the clock line can be observed by reading the sck pin. the idle state is determined by the ckp bit (sspcon1<4>). while in slave mode, the external clock is supplied by the external clock source on the sck pin. this external clock must meet the minimum high and low times as specified in the electrical specifications. while in sleep mode, the slave can transmit/receive data. when a byte is received, the device will wake-up from sleep. 17.3.7 slave select synchronization the ss pin allows a synchronous slave mode. the spi must be in slave mode with ss pin control enabled (sspcon1<3:0> = 04h). the pin must not be driven low for the ss pin to function as an input. the data latch must be high. when the ss pin is low, transmission and reception are enabled and the sdo pin is driven. when the ss pin goes high, the sdo pin is no longer driven, even if in the middle of a transmitted byte and becomes a floating output. external pull-up/pull-down resistors may be desirable depending on the application. when the spi module resets, the bit counter is forced to ? 0 ?. this can be done by either forcing the ss pin to a high level or clearing the sspen bit. to emulate two-wire communication, the sdo pin can be connected to the sdi pin. when the spi needs to operate as a receiver, the sdo pin can be configured as an input. this disables transmissions from the sdo. the sdi can always be left as an input (sdi function) since it cannot create a bus conflict. figure 17-4: slave synchronization waveform note 1: when the spi is in slave mode with ss pin control enabled (sspcon<3:0> = 0100 ), the spi module will reset if the ss pin is set to v dd . 2: if the spi is used in slave mode with cke set, then the ss pin control must be enabled. sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 sdo bit 7 bit 6 bit 7 sspif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag bit 0 bit 7 bit 0 next q4 cycle after q2
pic18f2585/2680/4585/4680 ds39625b-page 194 preliminary ? 2004 microchip technology inc. figure 17-5: spi? mode waveform (slave mode with cke = 0 ) figure 17-6: spi? mode waveform (slave mode with cke = 1 ) sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag optional next q4 cycle after q2 bit 0 sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif interrupt (smp = 0 ) cke = 1 ) cke = 1 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag not optional next q4 cycle after q2
? 2004 microchip technology inc. preliminary ds39625b-page 195 pic18f2585/2680/4585/4680 17.3.8 operation in power managed modes in spi master mode, module clocks may be operating at a different speed than when in full power mode; in the case of the sleep mode, all clocks are halted. in most power managed modes, a clock is provided to the peripherals. that clock should be from the primary clock source, the secondary clock (timer1 oscillator at 32.768 khz) or the intosc source. see section 2.7 ?clock sources and oscillator switching? for additional information. in most cases, the speed that the master clocks spi data is not important; however, this should be evaluated for each system. if mssp interrupts are enabled, they can wake the controller from sleep mode, or one of the idle modes, when the master completes sending data. if an exit from sleep or idle mode is not desired, mssp interrupts should be disabled. if the sleep mode is selected, all module clocks are halted and the transmission/reception will remain in that state until the devices wakes. after the device returns to run mode, the module will resume transmitting and receiving data. in spi slave mode, the spi transmit/receive shift register operates asynchronously to the device. this allows the device to be placed in any power managed mode and data to be shifted into the spi transmit/ receive shift register. when all 8 bits have been received, the mssp interrupt flag bit will be set and if enabled, will wake the device. 17.3.9 effects of a reset a reset disables the mssp module and terminates the current transfer. 17.3.10 bus mode compatibility table 17-1 shows the compatibility between the standard spi modes and the states of the ckp and cke control bits. table 17-1: spi? bus modes there is also a smp bit which controls when the data is sampled. table 17-2: registers associated with spi? operation standard spi? mode terminology control bits state ckp cke 0, 0 0 1 0, 1 0 0 1, 0 1 1 1, 1 1 0 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir1 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 trisa porta data direction register 52 trisc portc data direction register 52 sspbuf synchronous serial port receive buffer/transmit register 50 sspcon1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 50 sspstat smp cke d/a p s r/w ua bf 50 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the mssp in spi? mode. note 1: these bits are unimplemented in pic18f2x8x devices; always maintain these bits clear.
pic18f2585/2680/4585/4680 ds39625b-page 196 preliminary ? 2004 microchip technology inc. 17.4 i 2 c mode the mssp module in i 2 c mode fully implements all master and slave functions (including general call support) and provides interrupts on start and stop bits in hardware to determine a free bus (multi-master function). the mssp module implements the standard mode specifications, as well as 7-bit and 10-bit addressing. two pins are used for data transfer:  serial clock (scl) ? rc3/sck/scl  serial data (sda) ? rc4/sdi/sda the user must configure these pins as inputs or outputs through the trisc<4:3> bits. figure 17-7: mssp block diagram (i 2 c? mode) 17.4.1 registers the mssp module has six registers for i 2 c operation. these are:  mssp control register 1 (sspcon1)  mssp control register 2 (sspcon2)  mssp status register (sspstat)  serial receive/transmit buffer register (sspbuf)  mssp shift register (sspsr) ? not directly accessible  mssp address register (sspadd) sspcon1, sspcon2 and sspstat are the control and status registers in i 2 c mode operation. the sspcon1 and sspcon2 registers are readable and writable. the lower 6 bits of the sspstat are read-only. the upper two bits of the sspstat are read/write. sspsr is the shift register used for shifting data in or out. sspbuf is the buffer register to which data bytes are written to or read from. sspadd register holds the slave device address when the ssp is configured in i 2 c slave mode. when the ssp is configured in master mode, the lower seven bits of sspadd act as the baud rate generator reload value. in receive operations, sspsr and sspbuf together create a double-buffered receiver. when sspsr receives a complete byte, it is transferred to sspbuf and the sspif interrupt is set. during transmission, the sspbuf is not double- buffered. a write to sspbuf will write to both sspbuf and sspsr. read write sspsr reg match detect sspadd reg start and stop bit detect sspbuf reg internal data bus addr match set, reset s, p bits (sspstat reg) rc3/sck/scl rc4/sdi/sda shift clock msb lsb
? 2004 microchip technology inc. preliminary ds39625b-page 197 pic18f2585/2680/4585/4680 register 17-3: sspstat: mssp status register (i 2 c mode) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a psr/w ua bf bit 7 bit 0 bit 7 smp: slew rate control bit in master or slave mode: 1 = slew rate control disabled for standard speed mode (100 khz and 1 mhz) 0 = slew rate control enabled for high-speed mode (400 khz) bit 6 cke: smbus select bit in master or slave mode: 1 = enable smbus specific inputs 0 = disable smbus specific inputs bit 5 d/a : data/address bit in master mode: reserved. in slave mode: 1 = indicates that the last byte received or transmitted was data 0 = indicates that the last byte received or transmitted was address bit 4 p: stop bit 1 = indicates that a stop bit has been detected last 0 = stop bit was not detected last note: this bit is cleared on reset and when sspen is cleared. bit 3 s: start bit 1 = indicates that a start bit has been detected last 0 = start bit was not detected last note: this bit is cleared on reset and when sspen is cleared. bit 2 r/w : read/write bit information (i 2 c mode only) in slave mode: 1 = read 0 = write note: this bit holds the r/w bit information following the last address match. this bit is only valid from the address match to the next start bit, stop bit or not ack bit. in master mode: 1 = transmit is in progress 0 = transmit is not in progress note: oring this bit with sen, rsen, pen, rcen or acken will indicate if the mssp is in idle mode. bit 1 ua: update address bit (10-bit slave mode only) 1 = indicates that the user needs to update the address in the sspadd register 0 = address does not need to be updated bit 0 bf: buffer full status bit in transmit mode: 1 = receive complete, sspbuf is full 0 = receive not complete, sspbuf is empty in receive mode: 1 = data transmit in progress (does not include the ack and stop bits), sspbuf is full 0 = data transmit complete (does not include the ack and stop bits), sspbuf is empty legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 198 preliminary ? 2004 microchip technology inc. register 17-4: sspcon1: mssp control register 1 (i 2 c mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 bit 7 bit 0 bit 7 wcol: write collision detect bit in master transmit mode: 1 = a write to the sspbuf register was attempted while the i 2 c conditions were not valid for a transmission to be started (must be cleared in software) 0 = no collision in slave transmit mode: 1 = the sspbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision in receive mode (master or slave modes): this is a ?don?t care? bit. bit 6 sspov: receive overflow indicator bit in receive mode: 1 = a byte is received while the sspbuf register is still holding the previous byte (must be cleared in software) 0 = no overflow in transmit mode: this is a ?don?t care? bit in transmit mode. bit 5 sspen: synchronous serial port enable bit 1 = enables the serial port and configures the sda and scl pins as the serial port pins 0 = disables serial port and configures these pins as i/o port pins note: when enabled, the sda and scl pins must be properly configured as input or output. bit 4 ckp: sck release control bit in slave mode: 1 = release clock 0 = holds clock low (clock stretch), used to ensure data setup time in master mode: unused in this mode. bit 3-0 sspm3:sspm0: synchronous serial port mode select bits 1111 = i 2 c slave mode, 10-bit address with start and stop bit interrupts enabled 1110 = i 2 c slave mode, 7-bit address with start and stop bit interrupts enabled 1011 = i 2 c firmware controlled master mode (slave idle) 1000 = i 2 c master mode, clock = f osc /(4 * (sspadd + 1)) 0111 = i 2 c slave mode, 10-bit address 0110 = i 2 c slave mode, 7-bit address note: bit combinations not specifically listed here are either reserved or implemented in spi mode only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 199 pic18f2585/2680/4585/4680 register 17-5: sspcon2: mssp control register 2 (i 2 c mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 gcen ackstat ackdt acken (1) rcen (1) pen (1) rsen (1) sen (1) bit 7 bit 0 bit 7 gcen: general call enable bit (slave mode only) 1 = enable interrupt when a general call address (0000h) is received in the sspsr 0 = general call address disabled bit 6 ackstat: acknowledge status bit (master transmit mode only) 1 = acknowledge was not received from slave 0 = acknowledge was received from slave bit 5 ackdt: acknowledge data bit (master receive mode only) 1 = not acknowledge 0 = acknowledge note: value that will be transmitted when the user initiates an acknowledge sequence at the end of a receive. bit 4 acken: acknowledge sequence enable bit (master receive mode only) (1) 1 = initiate acknowledge sequence on sda and scl pins and transmit ackdt data bit. automatically cleared by hardware. 0 = acknowledge sequence idle bit 3 rcen: receive enable bit (master mode only) (1) 1 = enables receive mode for i 2 c 0 = receive idle bit 2 pen: stop condition enable bit (master mode only) (1) 1 = initiate stop condition on sda and scl pins. automatically cleared by hardware. 0 = stop condition idle bit 1 rsen: repeated start condition enable bit (master mode only) (1) 1 = initiate repeated start condition on sda and scl pins. automatically cleared by hardware. 0 = repeated start condition idle bit 0 sen: start condition enable/stretch enable bit (1) in master mode: 1 = initiate start condition on sda and scl pins. automatically cleared by hardware. 0 = start condition idle in slave mode: 1 = clock stretching is enabled for both slave transmit and slave receive (stretch enabled) 0 = clock stretching is disabled note 1: for bits acken, rcen, pen, rsen, sen: if the i 2 c module is not in the idle mode, these bits may not be set (no spooling) and the sspbuf may not be written (or writes to the sspbuf are disabled). legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 200 preliminary ? 2004 microchip technology inc. 17.4.2 operation the mssp module functions are enabled by setting mssp enable bit, sspen (sspcon<5>). the sspcon1 register allows control of the i 2 c operation. four mode selection bits (sspcon<3:0>) allow one of the following i 2 c modes to be selected: i 2 c master mode, clock = (f osc /4) x (sspadd + 1) i 2 c slave mode (7-bit address) i 2 c slave mode (10-bit address) i 2 c slave mode (7-bit address) with start and stop bit interrupts enabled i 2 c slave mode (10-bit address) with start and stop bit interrupts enabled i 2 c firmware controlled master mode, slave is idle selection of any i 2 c mode with the sspen bit set, forces the scl and sda pins to be open-drain, provided these pins are programmed to inputs by setting the appropriate trisc bits. to ensure proper operation of the module, pull-up resistors must be provided externally to the scl and sda pins. 17.4.3 slave mode in slave mode, the scl and sda pins must be config- ured as inputs (trisc<4:3> set). the mssp module will override the input state with the output data when required (slave-transmitter). the i 2 c slave mode hardware will always generate an interrupt on an address match. through the mode select bits, the user can also choose to interrupt on start and stop bits when an address is matched, or the data transfer after an address match is received, the hardware automati- cally will generate the acknowledge (ack ) pulse and load the sspbuf register with the received value currently in the sspsr register. any combination of the following conditions will cause the mssp module not to give this ack pulse:  the buffer full bit, bf (sspstat<0>), was set before the transfer was received.  the overflow bit, sspov (sspcon<6>), was set before the transfer was received. in this case, the sspsr register value is not loaded into the sspbuf, but bit sspif (pir1<3>) is set. the bf bit is cleared by reading the sspbuf register, while bit sspov is cleared through software. the scl clock input must have a minimum high and low for proper operation. the high and low times of the i 2 c specification, as well as the requirement of the mssp module, are shown in timing parameter 100 and parameter 101. 17.4.3.1 addressing once the mssp module has been enabled, it waits for a start condition to occur. following the start condition, the 8-bits are shifted into the sspsr register. all incoming bits are sampled with the rising edge of the clock (scl) line. the value of register sspsr<7:1> is compared to the value of the sspadd register. the address is compared on the falling edge of the eighth clock (scl) pulse. if the addresses match and the bf and sspov bits are clear, the following events occur: 1. the sspsr register value is loaded into the sspbuf register. 2. the buffer full bit, bf, is set. 3. an ack pulse is generated. 4. mssp interrupt flag bit, sspif (pir1<3>), is set (interrupt is generated, if enabled) on the falling edge of the ninth scl pulse. in 10-bit address mode, two address bytes need to be received by the slave. the five most significant bits (msbs) of the first address byte specify if this is a 10-bit address. bit r/w (sspstat<2>) must specify a write so the slave device will receive the second address byte. for a 10-bit address, the first byte would equal ? 11110 a9 a8 0 ?, where ? a9 ? and ? a8 ? are the two msbs of the address. the sequence of events for 10-bit address is as follows, with steps 7 through 9 for the slave-transmitter: 1. receive first (high) byte of address (bits sspif, bf and ua (sspstat<1>) are set). 2. update the sspadd register with second (low) byte of address (clears bit ua and releases the scl line). 3. read the sspbuf register (clears bit bf) and clear flag bit sspif. 4. receive second (low) byte of address (bits sspif, bf and ua are set). 5. update the sspadd register with the first (high) byte of address. if match releases scl line, this will clear bit ua. 6. read the sspbuf register (clears bit bf) and clear flag bit sspif. 7. receive repeated start condition. 8. receive first (high) byte of address (bits sspif and bf are set). 9. read the sspbuf register (clears bit bf) and clear flag bit sspif.
? 2004 microchip technology inc. preliminary ds39625b-page 201 pic18f2585/2680/4585/4680 17.4.3.2 reception when the r/w bit of the address byte is clear and an address match occurs, the r/w bit of the sspstat register is cleared. the received address is loaded into the sspbuf register and the sda line is held low (ack ). when the address byte overflow condition exists, then the no acknowledge (ack ) pulse is given. an overflow condition is defined as either bit bf (sspstat<0>) is set, or bit sspov (sspcon1<6>) is set. an mssp interrupt is generated for each data transfer byte. flag bit, sspif (pir1<3>), must be cleared in software. the sspstat register is used to determine the status of the byte. if sen is enabled (sspcon2<0> = 1 ), rc3/sck/scl will be held low (clock stretch) following each data transfer. the clock must be released by setting bit ckp (sspcon<4>). see section 17.4.4 ?clock stretching? for more detail. 17.4.3.3 transmission when the r/w bit of the incoming address byte is set and an address match occurs, the r/w bit of the sspstat register is set. the received address is loaded into the sspbuf register. the ack pulse will be sent on the ninth bit and pin rc3/sck/scl is held low regardless of sen (see section 17.4.4 ?clock stretching? for more detail). by stretching the clock, the master will be unable to assert another clock pulse until the slave is done preparing the transmit data. the transmit data must be loaded into the sspbuf register which also loads the sspsr register. then pin rc3/ sck/scl should be enabled by setting bit, ckp (sspcon1<4>). the eight data bits are shifted out on the falling edge of the scl input. this ensures that the sda signal is valid during the scl high time (figure 17-9). the ack pulse from the master-receiver is latched on the rising edge of the ninth scl input pulse. if the sda line is high (not ack ), then the data transfer is complete. in this case, when the ack is latched by the slave, the slave logic is reset (resets sspstat regis- ter) and the slave monitors for another occurrence of the start bit. if the sda line was low (ack ), the next transmit data must be loaded into the sspbuf register. again, pin rc3/sck/scl must be enabled by setting bit ckp. an mssp interrupt is generated for each data transfer byte. the sspif bit must be cleared in software and the sspstat register is used to determine the status of the byte. the sspif bit is set on the falling edge of the ninth clock pulse.
pic18f2585/2680/4585/4680 ds39625b-page 202 preliminary ? 2004 microchip technology inc. figure 17-8: i 2 c? slave mode timing with sen = 0 (reception, 7-bit address) sda scl sspif bf (sspstat<0>) sspov (sspcon1<6>) s 12345678912345678912345 789 p a7 a6 a5 a4 a3 a2 a1 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d1 d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspbuf is read bus master terminates transfer sspov is set because sspbuf is still full. ack is not sent. d2 6 (pir1<3>) ckp (ckp does not reset to ? 0 ? when sen = 0 )
? 2004 microchip technology inc. preliminary ds39625b-page 203 pic18f2585/2680/4585/4680 figure 17-9: i 2 c? slave mode timing (transmission, 7-bit address) sda scl sspif (pir1<3>) bf (sspstat<0>) a6 a5 a4 a3 a2 a1 d6 d5 d4 d3 d2 d1 d0 1 2 3 4 5 6 7 8 2 3 4 5 6 7 8 9 sspbuf is written in software cleared in software from sspif isr data in sampled s ack transmitting data r/w = 1 ack receiving address a7 d7 9 1 d6 d5 d4 d3 d2 d1 d0 2 3 4 5 6 7 8 9 sspbuf is written in software cleared in software from sspif isr transmitting data d7 1 ckp p ack ckp is set in software ckp is set in software scl held low while cpu responds to sspif
pic18f2585/2680/4585/4680 ds39625b-page 204 preliminary ? 2004 microchip technology inc. figure 17-10: i 2 c? slave mode timing with sen = 0 (reception, 10-bit address) sda scl sspif bf (sspstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9a8 a7 a6 a5 a4a3 a2a1 a0 d7 d6d5d4d3 d1d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 (pir1<3>) cleared in software receive second byte of address cleared by hardware when sspadd is updated with low byte of address ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag ack ckp 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspcon1<6>) sspov is set because sspbuf is still full. ack is not sent. (ckp does not reset to ? 0 ? when sen = 0 ) clock is held low until update of sspadd has taken place
? 2004 microchip technology inc. preliminary ds39625b-page 205 pic18f2585/2680/4585/4680 figure 17-11: i 2 c? slave mode timing (transmission, 10-bit address) sda scl sspif bf (sspstat<0>) s 1234 5 6789 12345678 9 12345 789 p 1 1 1 1 0 a9a8 a7 a6a5a4a3a2a1 a0 1 1 1 1 0 a8 r/w =1 ack ack r/w = 0 ack receive first byte of address cleared in software bus master terminates transfer a9 6 (pir1<3>) receive second byte of address cleared by hardware when sspadd is updated with low byte of address ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address. sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag receive first byte of address 12345 789 d7 d6 d5 d4 d3 d1 ack d2 6 transmitting data byte d0 dummy read of sspbuf to clear bf flag sr cleared in software write of sspbuf initiates transmit cleared in software completion of clears bf flag ckp (sspcon1<4>) ckp is set in software ckp is automatically cleared in hardware, holding scl low clock is held low until update of sspadd has taken place data transmission clock is held low until ckp is set to ?1? bf flag is clear third address sequence at the end of the
pic18f2585/2680/4585/4680 ds39625b-page 206 preliminary ? 2004 microchip technology inc. 17.4.4 clock stretching both 7 and 10-bit slave modes implement automatic clock stretching during a transmit sequence. the sen bit (sspcon2<0>) allows clock stretching to be enabled during receives. setting sen will cause the scl pin to be held low at the end of each data receive sequence. 17.4.4.1 clock stretching for 7-bit slave receive mode (sen = 1 ) in 7-bit slave receive mode, on the falling edge of the ninth clock at the end of the ack sequence if the bf bit is set, the ckp bit in the sspcon1 register is automatically cleared, forcing the scl output to be held low. the ckp being cleared to ? 0 ? will assert the scl line low. the ckp bit must be set in the user?s isr before reception is allowed to continue. by holding the scl line low, the user has time to service the isr and read the contents of the sspbuf before the master device can initiate another receive sequence. this will prevent buffer overruns from occurring (see figure 17-13). 17.4.4.2 clock stretching for 10-bit slave receive mode (sen = 1 ) in 10-bit slave receive mode during the address sequence, clock stretching automatically takes place but ckp is not cleared. during this time, if the ua bit is set after the ninth clock, clock stretching is initiated. the ua bit is set after receiving the upper byte of the 10-bit address and following the receive of the second byte of the 10-bit address with the r/w bit cleared to ? 0 ?. the release of the clock line occurs upon updating sspadd. clock stretching will occur on each data receive sequence as described in 7-bit mode. 17.4.4.3 clock stretching for 7-bit slave transmit mode 7-bit slave transmit mode implements clock stretching by clearing the ckp bit after the falling edge of the ninth clock if the bf bit is clear. this occurs regardless of the state of the sen bit. the user?s isr must set the ckp bit before transmis- sion is allowed to continue. by holding the scl line low, the user has time to service the isr and load the contents of the sspbuf before the master device can initiate another transmit sequence (see figure 17-9). 17.4.4.4 clock stretching for 10-bit slave transmit mode in 10-bit slave transmit mode, clock stretching is controlled during the first two address sequences by the state of the ua bit, just as it is in 10-bit slave receive mode. the first two addresses are followed by a third address sequence which contains the high- order bits of the 10-bit address and the r/w bit set to ? 1 ?. after the third address sequence is performed, the ua bit is not set, the module is now configured in transmit mode and clock stretching is controlled by the bf flag as in 7-bit slave transmit mode (see figure 17-11). note 1: if the user reads the contents of the sspbuf before the falling edge of the ninth clock, thus clearing the bf bit, the ckp bit will not be cleared and clock stretching will not occur. 2: the ckp bit can be set in software regardless of the state of the bf bit. the user should be careful to clear the bf bit in the isr before the next receive sequence in order to prevent an overflow condition. note: if the user polls the ua bit and clears it by updating the sspadd register before the falling edge of the ninth clock occurs and if the user hasn?t cleared the bf bit by read- ing the sspbuf register before that time, then the ckp bit will still not be asserted low. clock stretching on the basis of the state of the bf bit only occurs during a data sequence, not an address sequence. note 1: if the user loads the contents of sspbuf, setting the bf bit before the falling edge of the ninth clock, the ckp bit will not be cleared and clock stretching will not occur. 2: the ckp bit can be set in software regardless of the state of the bf bit.
? 2004 microchip technology inc. preliminary ds39625b-page 207 pic18f2585/2680/4585/4680 17.4.4.5 clock synchronization and the ckp bit when the ckp bit is cleared, the scl output is forced to ? 0 ?. however, setting the ckp bit will not assert the scl output low until the scl output is already sampled low. therefore, the ckp bit will not assert the scl line until an external i 2 c master device has already asserted the scl line. the scl output will remain low until the ckp bit is set and all other devices on the i 2 c bus have deasserted scl. this ensures that a write to the ckp bit will not violate the minimum high time requirement for scl (see figure 17-12). figure 17-12: clock synchronization timing sda scl dx ? 1 dx wr q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 sspcon ckp master device deasserts clock master device asserts clock
pic18f2585/2680/4585/4680 ds39625b-page 208 preliminary ? 2004 microchip technology inc. figure 17-13: i 2 c? slave mode timing with sen = 1 (reception, 7-bit address) sda scl sspif bf (sspstat<0>) sspov (sspcon1<6>) s 1 234 56 7 89 1 2 345 67 89 1 23 45 7 89 p a7 a6 a5 a4 a3 a2 a1 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d1 d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspbuf is read bus master terminates transfer sspov is set because sspbuf is still full. ack is not sent. d2 6 (pir1<3>) ckp ckp written to ? 1 ? in if bf is cleared prior to the falling edge of the 9th clock, ckp will not be reset to ? 0 ? and no clock stretching will occur software clock is held low until ckp is set to ? 1 ? clock is not held low because buffer full bit is clear prior to falling edge of 9th clock clock is not held low because ack = 1 bf is set after falling edge of the 9th clock, ckp is reset to ? 0 ? and clock stretching occurs
? 2004 microchip technology inc. preliminary ds39625b-page 209 pic18f2585/2680/4585/4680 figure 17-14: i 2 c? slave mode timing sen = 1 (reception, 10-bit address) sda scl sspif bf (sspstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9a8 a7 a6 a5a4a3a2a1 a0 d7d6d5d4d3 d1d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 (pir1<3>) cleared in software receive second byte of address cleared by hardware when sspadd is updated with low byte of address after falling edge ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address after falling edge sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag ack ckp 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspcon1<6>) ckp written to ? 1 ? note: an update of the sspadd register before the falling edge of the ninth clock will have no effect on ua and ua will remain set. note: an update of the sspadd register before the falling edge of the ninth clock will have no effect on ua and ua will remain set. in software clock is held low until update of sspadd has taken place of ninth clock of ninth clock sspov is set because sspbuf is still full. ack is not sent. dummy read of sspbuf to clear bf flag clock is held low until ckp is set to ? 1 ? clock is not held low because ack = 1
pic18f2585/2680/4585/4680 ds39625b-page 210 preliminary ? 2004 microchip technology inc. 17.4.5 general call address support the addressing procedure for the i 2 c bus is such that the first byte after the start condition usually determines which device will be the slave addressed by the master. the exception is the general call address which can address all devices. when this address is used, all devices should, in theory, respond with an acknowledge. the general call address is one of eight addresses reserved for specific purposes by the i 2 c protocol. it consists of all ? 0 ?s with r/w = 0 . the general call address is recognized when the general call enable bit, gcen, is enabled (sspcon2<7> set). following a start bit detect, 8 bits are shifted into the sspsr and the address is compared against the sspadd. it is also compared to the general call address and fixed in hardware. if the general call address matches, the sspsr is transferred to the sspbuf, the bf flag bit is set (eighth bit) and on the falling edge of the ninth bit (ack bit), the sspif interrupt flag bit is set. when the interrupt is serviced, the source for the interrupt can be checked by reading the contents of the sspbuf. the value can be used to determine if the address was device specific or a general call address. in 10-bit mode, the sspadd is required to be updated for the second half of the address to match and the ua bit is set (sspstat<1>). if the general call address is sampled when the gcen bit is set, while the slave is configured in 10-bit address mode, then the second half of the address is not necessary, the ua bit will not be set and the slave will begin receiving data after the acknowledge (figure 17-15). figure 17-15: slave mode general call address sequence (7 or 10-bit address mode) sda scl s sspif bf (sspstat<0>) sspov (sspcon1<6>) cleared in software sspbuf is read r/w = 0 ack general call address address is compared to general call address gcen (sspcon2<7>) receiving data ack 1 234 567891 234 56 789 d7 d6 d5 d4 d3 d2 d1 d0 after ack , set interrupt ? 0 ? ? 1 ?
? 2004 microchip technology inc. preliminary ds39625b-page 211 pic18f2585/2680/4585/4680 17.4.6 master mode master mode is enabled by setting and clearing the appropriate sspm bits in sspcon1 and by setting the sspen bit. in master mode, the scl and sda lines are manipulated by the mssp hardware. master mode of operation is supported by interrupt generation on the detection of the start and stop conditions. the stop (p) and start (s) bits are cleared from a reset or when the mssp module is disabled. control of the i 2 c bus may be taken when the p bit is set or the bus is idle, with both the s and p bits clear. in firmware controlled master mode, user code conducts all i 2 c bus operations based on start and stop bit conditions. once master mode is enabled, the user has six options. 1. assert a start condition on sda and scl. 2. assert a repeated start condition on sda and scl. 3. write to the sspbuf register initiating transmission of data/address. 4. configure the i 2 c port to receive data. 5. generate an acknowledge condition at the end of a received byte of data. 6. generate a stop condition on sda and scl. the following events will cause the ssp interrupt flag bit, sspif, to be set (ssp interrupt, if enabled):  start condition  stop condition  data transfer byte transmitted/received  acknowledge transmit  repeated start figure 17-16: mssp block diagram (i 2 c? master mode) note: the mssp module, when configured in i 2 c master mode, does not allow queueing of events. for instance, the user is not allowed to initiate a start condition and immediately write the sspbuf register to initiate transmission before the start condition is complete. in this case, the sspbuf will not be written to and the wcol bit will be set, indicating that a write to the sspbuf did not occur. read write sspsr start bit, stop bit, sspbuf internal data bus set/reset, s, p, wcol (sspstat) shift clock msb lsb sda acknowledge generate stop bit detect write collision detect clock arbitration state counter for end of xmit/rcv scl scl in bus collision sda in receive enable clock cntl clock arbitrate/wcol detect (hold off clock source) sspadd<6:0> baud set sspif, bclif reset ackstat, pen (sspcon2) rate generator sspm3:sspm0 start bit detect
pic18f2585/2680/4585/4680 ds39625b-page 212 preliminary ? 2004 microchip technology inc. 17.4.6.1 i 2 c master mode operation the master device generates all of the serial clock pulses and the start and stop conditions. a transfer is ended with a stop condition or with a repeated start condition. since the repeated start condition is also the beginning of the next serial transfer, the i 2 c bus will not be released. in master transmitter mode, serial data is output through sda, while scl outputs the serial clock. the first byte transmitted contains the slave address of the receiving device (7 bits) and the read/write (r/w ) bit. in this case, the r/w bit will be logic ? 0 ?. serial data is transmitted 8 bits at a time. after each byte is transmit- ted, an acknowledge bit is received. start and stop conditions are output to indicate the beginning and the end of a serial transfer. in master receive mode, the first byte transmitted contains the slave address of the transmitting device (7 bits) and the r/w bit. in this case, the r/w bit will be logic ? 1 ? thus, the first byte transmitted is a 7-bit slave address followed by a ? 1 ? to indicate the receive bit. serial data is received via sda, while scl outputs the serial clock. serial data is received 8 bits at a time. after each byte is received, an acknowledge bit is transmit- ted. start and stop conditions indicate the beginning and end of transmission. the baud rate generator used for the spi mode operation is used to set the scl clock frequency for either 100 khz, 400 khz or 1 mhz i 2 c operation. see section 17.4.7 ?baud rate? for more detail. a typical transmit sequence would go as follows: 1. the user generates a start condition by setting the start enable bit, sen (sspcon2<0>). 2. sspif is set. the mssp module will wait the required start time before any other operation takes place. 3. the user loads the sspbuf with the slave address to transmit. 4. address is shifted out the sda pin until all 8 bits are transmitted. 5. the mssp module shifts in the ack bit from the slave device and writes its value into the sspcon2 register (sspcon2<6>). 6. the mssp module generates an interrupt at the end of the ninth clock cycle by setting the sspif bit. 7. the user loads the sspbuf with eight bits of data. 8. data is shifted out the sda pin until all 8 bits are transmitted. 9. the mssp module shifts in the ack bit from the slave device and writes its value into the sspcon2 register (sspcon2<6>). 10. the mssp module generates an interrupt at the end of the ninth clock cycle by setting the sspif bit. 11. the user generates a stop condition by setting the stop enable bit, pen (sspcon2<2>). 12. interrupt is generated once the stop condition is complete.
? 2004 microchip technology inc. preliminary ds39625b-page 213 pic18f2585/2680/4585/4680 17.4.7 baud rate in i 2 c master mode, the baud rate generator (brg) reload value is placed in the lower 7 bits of the sspadd register (figure 17-17). when a write occurs to sspbuf, the baud rate generator will automatically begin counting. the brg counts down to ? 0 ? and stops until another reload has taken place. the brg count is decremented twice per instruction cycle (t cy ) on the q2 and q4 clocks. in i 2 c master mode, the brg is reloaded automatically. once the given operation is complete (i.e., transmis- sion of the last data bit is followed by ack ), the internal clock will automatically stop counting and the scl pin will remain in its last state. table 17-3 demonstrates clock rates based on instruction cycles and the brg value loaded into sspadd. figure 17-17: baud rate generator block diagram table 17-3: i 2 c? clock rate w/brg sspm3:sspm0 brg down counter clko f osc /4 sspadd<6:0> sspm3:sspm0 scl reload control reload f cy f cy *2 brg value f scl (2 rollovers of brg) 10 mhz 20 mhz 19h 400 khz (1) 10 mhz 20 mhz 20h 312.5 khz 10 mhz 20 mhz 64h 100 khz 4 mhz 8 mhz 0ah 400 khz (1) 4 mhz 8 mhz 0dh 308 khz 4 mhz 8 mhz 28h 100 khz 1 mhz 2 mhz 03h 333 khz (1) 1 mhz 2 mhz 0ah 100 khz 1 mhz 2 mhz 00h 1 mhz (1) note 1: the i 2 c? interface does not conform to the 400 khz i 2 c specification (which applies to rates greater than 100 khz) in all details, but may be used with care where higher rates are required by the application.
pic18f2585/2680/4585/4680 ds39625b-page 214 preliminary ? 2004 microchip technology inc. 17.4.7.1 clock arbitration clock arbitration occurs when the master, during any receive, transmit or repeated start/stop condition, deasserts the scl pin (scl allowed to float high). when the scl pin is allowed to float high, the baud rate generator (brg) is suspended from counting until the scl pin is actually sampled high. when the scl pin is sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and begins counting. this ensures that the scl high time will always be at least one brg rollover count in the event that the clock is held low by an external device (figure 17-18). figure 17-18: baud rate generator timing with clock arbitration sda scl scl deasserted but slave holds dx ? 1 dx brg scl is sampled high, reload takes place and brg starts its count 03h 02h 01h 00h (hold off) 03h 02h reload brg value scl low (clock arbitration) scl allowed to transition high brg decrements on q2 and q4 cycles
? 2004 microchip technology inc. preliminary ds39625b-page 215 pic18f2585/2680/4585/4680 17.4.8 i 2 c master mode start condition timing to initiate a start condition, the user sets the start enable bit, sen (sspcon2<0>). if the sda and scl pins are sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and starts its count. if scl and sda are both sampled high when the baud rate generator times out (t brg ), the sda pin is driven low. the action of the sda being driven low while scl is high is the start condition and causes the s bit (sspstat<3>) to be set. following this, the baud rate generator is reloaded with the contents of sspadd<6:0> and resumes its count. when the baud rate generator times out (t brg ), the sen bit (sspcon2<0>) will be automatically cleared by hardware, the baud rate generator is suspended, leaving the sda line held low and the start condition is complete. 17.4.8.1 wcol status flag if the user writes the sspbuf when a start sequence is in progress, the wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 17-19: first start bit timing note: if at the beginning of the start condition, the sda and scl pins are already sam- pled low, or if during the start condition, the scl line is sampled low before the sda line is driven low, a bus collision occurs, the bus collision interrupt flag, bclif, is set, the start condition is aborted and the i 2 c module is reset into its idle state. note: because queueing of events is not allowed, writing to the lower 5 bits of sspcon2 is disabled until the start condition is complete. sda scl s t brg 1st bit 2nd bit t brg sda = 1 , at completion of start bit, scl = 1 write to sspbuf occurs here t brg hardware clears sen bit t brg write to sen bit occurs here set s bit (sspstat<3>) and sets sspif bit
pic18f2585/2680/4585/4680 ds39625b-page 216 preliminary ? 2004 microchip technology inc. 17.4.9 i 2 c master mode repeated start condition timing a repeated start condition occurs when the rsen bit (sspcon2<1>) is programmed high and the i 2 c logic module is in the idle state. when the rsen bit is set, the scl pin is asserted low. when the scl pin is sampled low, the baud rate generator is loaded with the contents of sspadd<5:0> and begins counting. the sda pin is released (brought high) for one baud rate generator count (t brg ). when the baud rate generator times out, if sda is sampled high, the scl pin will be deasserted (brought high). when scl is sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and begins count- ing. sda and scl must be sampled high for one t brg . this action is then followed by assertion of the sda pin (sda = 0 ) for one t brg while scl is high. following this, the rsen bit (sspcon2<1>) will be automatically cleared and the baud rate generator will not be reloaded, leaving the sda pin held low. as soon as a start condition is detected on the sda and scl pins, the s bit (sspstat<3>) will be set. the sspif bit will not be set until the baud rate generator has timed out. immediately following the sspif bit getting set, the user may write the sspbuf with the 7-bit address in 7-bit mode, or the default first address in 10-bit mode. after the first eight bits are transmitted and an ack is received, the user may then transmit an additional eight bits of address (10-bit mode) or eight bits of data (7-bit mode). 17.4.9.1 wcol status flag if the user writes the sspbuf when a repeated start sequence is in progress, the wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 17-20: repeat start condition waveform note 1: if rsen is programmed while any other event is in progress, it will not take effect. 2: a bus collision during the repeated start condition occurs if:  sda is sampled low when scl goes from low-to-high.  scl goes low before sda is asserted low. this may indicate that another master is attempting to transmit a data ? 1 ?. note: because queueing of events is not allowed, writing of the lower 5 bits of sspcon2 is disabled until the repeated start condition is complete. sda scl sr = repeated start write to sspcon2 write to sspbuf occurs here falling edge of ninth clock, end of xmit at completion of start bit, hardware clears rsen bit 1st bit set s (sspstat<3>) t brg t brg sda = 1 , sda = 1 , scl (no change). scl = 1 occurs here. t brg t brg t brg and sets sspif
? 2004 microchip technology inc. preliminary ds39625b-page 217 pic18f2585/2680/4585/4680 17.4.10 i 2 c master mode transmission transmission of a data byte, a 7-bit address or the other half of a 10-bit address is accomplished by simply writing a value to the sspbuf register. this action will set the buffer full flag bit, bf and allow the baud rate generator to begin counting and start the next transmission. each bit of address/data will be shifted out onto the sda pin after the falling edge of scl is asserted (see data hold time specification parameter 106). scl is held low for one baud rate generator rollover count (t brg ). data should be valid before scl is released high (see data setup time specification parameter 107). when the scl pin is released high, it is held that way for t brg . the data on the sda pin must remain stable for that duration and some hold time after the next falling edge of scl. after the eighth bit is shifted out (the falling edge of the eighth clock), the bf flag is cleared and the master releases sda. this allows the slave device being addressed to respond with an ack bit during the ninth bit time if an address match occurred, or if data was received properly. the status of ack is written into the ackdt bit on the falling edge of the ninth clock. if the master receives an acknowledge, the acknowledge status bit, ackstat, is cleared. if not, the bit is set. after the ninth clock, the sspif bit is set and the master clock (baud rate generator) is suspended until the next data byte is loaded into the sspbuf, leaving scl low and sda unchanged (figure 17-21). after the write to the sspbuf, each bit of address will be shifted out on the falling edge of scl until all seven address bits and the r/w bit are completed. on the fall- ing edge of the eighth clock, the master will deassert the sda pin, allowing the slave to respond with an acknowledge. on the falling edge of the ninth clock, the master will sample the sda pin to see if the address was recognized by a slave. the status of the ack bit is loaded into the ackstat status bit (sspcon2<6>). following the falling edge of the ninth clock transmis- sion of the address, the sspif is set, the bf flag is cleared and the baud rate generator is turned off until another write to the sspbuf takes place, holding scl low and allowing sda to float. 17.4.10.1 bf status flag in transmit mode, the bf bit (sspstat<0>) is set when the cpu writes to sspbuf and is cleared when all 8 bits are shifted out. 17.4.10.2 wcol status flag if the user writes the sspbuf when a transmit is already in progress (i.e., sspsr is still shifting out a data byte), the wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). wcol must be cleared in software. 17.4.10.3 ackstat status flag in transmit mode, the ackstat bit (sspcon2<6>) is cleared when the slave has sent an acknowledge (ack = 0 ) and is set when the slave does not acknowl- edge (ack = 1 ). a slave sends an acknowledge when it has recognized its address (including a general call), or when the slave has properly received its data. 17.4.11 i 2 c master mode reception master mode reception is enabled by programming the receive enable bit, rcen (sspcon2<3>). the baud rate generator begins counting and on each rollover, the state of the scl pin changes (high-to-low/ low-to-high) and data is shifted into the sspsr. after the falling edge of the eighth clock, the receive enable flag is automatically cleared, the contents of the sspsr are loaded into the sspbuf, the bf flag bit is set, the sspif flag bit is set and the baud rate generator is suspended from counting, holding scl low. the mssp is now in idle state awaiting the next command. when the buffer is read by the cpu, the bf flag bit is automatically cleared. the user can then send an acknowledge bit at the end of reception by setting the acknowledge sequence enable bit, acken (sspcon2<4>). 17.4.11.1 bf status flag in receive operation, the bf bit is set when an address or data byte is loaded into sspbuf from sspsr. it is cleared when the sspbuf register is read. 17.4.11.2 sspov status flag in receive operation, the sspov bit is set when 8 bits are received into the sspsr and the bf flag bit is already set from a previous reception. 17.4.11.3 wcol status flag if the user writes the sspbuf when a receive is already in progress (i.e., sspsr is still shifting in a data byte), the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur). note: the mssp module must be in an idle state before the rcen bit is set or the rcen bit will be disregarded.
pic18f2585/2680/4585/4680 ds39625b-page 218 preliminary ? 2004 microchip technology inc. figure 17-21: i 2 c? master mode waveform (transmission, 7 or 10-bit address) sda scl sspif bf (sspstat<0>) sen a7 a6 a5 a4 a3 a2 a1 ack = 0 d7 d6 d5 d4 d3 d2 d1 d0 ack transmitting data or second half r/w = 0 transmit address to slave 123456789 123456789 p cleared in software service routine sspbuf is written in software from ssp interrupt after start condition, sen cleared by hardware s sspbuf written with 7-bit address and r/w , start transmit scl held low while cpu responds to sspif sen = 0 of 10-bit address write sspcon2<0> sen = 1 , start condition begins from slave, clear ackstat bit sspcon2<6> ackstat in sspcon2 = 1 cleared in software sspbuf written pen r/w cleared in software
? 2004 microchip technology inc. preliminary ds39625b-page 219 pic18f2585/2680/4585/4680 figure 17-22: i 2 c? master mode waveform (reception, 7-bit address) p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sda scl 12 3 4 5 6 7 8 9 12 3 4 5 6 7 89 12 34 bus master terminates transfer ack receiving data from slave receiving data from slave d0 d1 d2 d3 d4 d5 d6 d7 ack r/w = 1 transmit address to slave sspif bf ack is not sent write to sspcon2<0> (sen = 1 ), write to sspbuf occurs here, ack from slave master configured as a receiver by programming sspcon2<3> (rcen = 1 ) pen bit = 1 written here data shifted in on falling edge of clk cleared in software start xmit sen = 0 sspov sda = 0 , scl = 1 while cpu (sspstat<0>) ack cleared in software cleared in software set sspif interrupt at end of receive set p bit (sspstat<4>) and sspif ack from master set sspif at end set sspif interrupt at end of acknowledge sequence set sspif interrupt at end of acknow- ledge sequence of receive set acken, start acknowledge sequence sda = ackdt = 1 rcen cleared automatically rcen = 1 , start next receive write to sspcon2<4> to start acknowledge sequence sda = ackdt (sspcon2<5>) = 0 rcen cleared automatically responds to sspif acken begin start condition cleared in software sda = ackdt = 0 last bit is shifted into sspsr and contents are unloaded into sspbuf cleared in software sspov is set because sspbuf is still full
pic18f2585/2680/4585/4680 ds39625b-page 220 preliminary ? 2004 microchip technology inc. 17.4.12 acknowledge sequence timing an acknowledge sequence is enabled by setting the acknowledge sequence enable bit, acken (sspcon2<4>). when this bit is set, the scl pin is pulled low and the contents of the acknowledge data bit are presented on the sda pin. if the user wishes to gen- erate an acknowledge, then the ackdt bit should be cleared. if not, the user should set the ackdt bit before starting an acknowledge sequence. the baud rate generator then counts for one rollover period (t brg ) and the scl pin is deasserted (pulled high). when the scl pin is sampled high (clock arbitration), the baud rate generator counts for t brg . the scl pin is then pulled low. following this, the acken bit is automatically cleared, the baud rate generator is turned off and the mssp module then goes into idle mode (figure 17-23). 17.4.12.1 wcol status flag if the user writes the sspbuf when an acknowledge sequence is in progress, then wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). 17.4.13 stop condition timing a stop bit is asserted on the sda pin at the end of a receive/transmit by setting the stop sequence enable bit, pen (sspcon2<2>). at the end of a receive/ transmit, the scl line is held low after the falling edge of the ninth clock. when the pen bit is set, the master will assert the sda line low. when the sda line is sampled low, the baud rate generator is reloaded and counts down to ? 0 ?. when the baud rate generator times out, the scl pin will be brought high and one t brg (baud rate generator rollover count) later, the sda pin will be deasserted. when the sda pin is sampled high while scl is high, the p bit (sspstat<4>) is set. a t brg later, the pen bit is cleared and the sspif bit is set (figure 17-24). 17.4.13.1 wcol status flag if the user writes the sspbuf when a stop sequence is in progress, then the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 17-23: acknowledge sequence waveform figure 17-24: stop cond ition receive or transmit mode note: t brg = one baud rate generator period. sda scl set sspif at the acknowledge sequence starts here, write to sspcon2 acken automatically cleared cleared in t brg t brg end of receive 8 acken = 1 , ackdt = 0 d0 9 sspif software set sspif at the end of acknowledge sequence cleared in software ack scl sda sda asserted low before rising edge of clock write to sspcon2, set pen falling edge of scl = 1 for t brg , followed by sda = 1 for t brg 9th clock scl brought high after t brg note: t brg = one baud rate generator period. t brg t brg after sda sampled high. p bit (sspstat<4>) is set. t brg to setup stop condition ack p t brg pen bit (sspcon2<2>) is cleared by hardware and the sspif bit is set
? 2004 microchip technology inc. preliminary ds39625b-page 221 pic18f2585/2680/4585/4680 17.4.14 sleep operation while in sleep mode, the i 2 c module can receive addresses or data and when an address match or complete byte transfer occurs, wake the processor from sleep (if the mssp interrupt is enabled). 17.4.15 effect of a reset a reset disables the mssp module and terminates the current transfer. 17.4.16 multi-master mode in multi-master mode, the interrupt generation on the detection of the start and stop conditions allows the determination of when the bus is free. the stop (p) and start (s) bits are cleared from a reset or when the mssp module is disabled. control of the i 2 c bus may be taken when the p bit (sspstat<4>) is set, or the bus is idle, with both the s and p bits clear. when the bus is busy, enabling the ssp interrupt will generate the interrupt when the stop condition occurs. in multi-master operation, the sda line must be monitored for arbitration to see if the signal level is the expected output level. this check is performed in hardware with the result placed in the bclif bit. the states where arbitration can be lost are:  address transfer  data transfer  a start condition  a repeated start condition  an acknowledge condition 17.4.17 multi-master communication, bus collision and bus arbitration multi-master mode support is achieved by bus arbitra- tion. when the master outputs address/data bits onto the sda pin, arbitration takes place when the master outputs a ? 1 ? on sda, by letting sda float high and another master asserts a ? 0 ?. when the scl pin floats high, data should be stable. if the expected data on sda is a ? 1 ? and the data sampled on the sda pin = 0 , then a bus collision has taken place. the master will set the bus collision interrupt flag, bclif and reset the i 2 c port to its idle state (figure 17-25). if a transmit was in progress when the bus collision occurred, the transmission is halted, the bf flag is cleared, the sda and scl lines are deasserted and the sspbuf can be written to. when the user services the bus collision interrupt service routine and if the i 2 c bus is free, the user can resume communication by asserting a start condition. if a start, repeated start, stop or acknowledge condition was in progress when the bus collision occurred, the condition is aborted, the sda and scl lines are deasserted and the respective control bits in the sspcon2 register are cleared. when the user ser- vices the bus collision interrupt service routine and if the i 2 c bus is free, the user can resume communication by asserting a start condition. the master will continue to monitor the sda and scl pins. if a stop condition occurs, the sspif bit will be set. a write to the sspbuf will start the transmission of data at the first data bit regardless of where the transmitter left off when the bus collision occurred. in multi-master mode, the interrupt generation on the detection of start and stop conditions allows the determi- nation of when the bus is free. control of the i 2 c bus can be taken when the p bit is set in the sspstat register, or the bus is idle and the s and p bits are cleared. figure 17-25: bus collision timing for transmit and acknowledge sda scl bclif sda released sda line pulled low by another source sample sda. while scl is high, data doesn?t match what is driven bus collision has occurred. set bus collision interrupt (bclif) by the master. by master data changes while scl = 0
pic18f2585/2680/4585/4680 ds39625b-page 222 preliminary ? 2004 microchip technology inc. 17.4.17.1 bus collision during a start condition during a start condition, a bus collision occurs if: a) sda or scl are sampled low at the beginning of the start condition (figure 17-26). b) scl is sampled low before sda is asserted low (figure 17-27). during a start condition, both the sda and the scl pins are monitored. if the sda pin is already low, or the scl pin is already low, then all of the following occur:  the start condition is aborted,  the bclif flag is set; and  the mssp module is reset to its idle state (figure 17-26). the start condition begins with the sda and scl pins deasserted. when the sda pin is sampled high, the baud rate generator is loaded from sspadd<6:0> and counts down to 0. if the scl pin is sampled low while sda is high, a bus collision occurs because it is assumed that another master is attempting to drive a data ? 1 ? during the start condition. if the sda pin is sampled low during this count, the brg is reset and the sda line is asserted early (figure 17-28). if, however, a ? 1 ? is sampled on the sda pin, the sda pin is asserted low at the end of the brg count. the baud rate generator is then reloaded and counts down to 0 and during this time, if the scl pins are sampled as ? 0 ?, a bus collision does not occur. at the end of the brg count, the scl pin is asserted low. figure 17-26: bus collision during start condition (sda only) note: the reason that bus collision is not a factor during a start condition is that no two bus masters can assert a start condition at the exact same time. therefore, one master will always assert sda before the other. this condition does not cause a bus collision because the two masters must be allowed to arbitrate the first address following the start condition. if the address is the same, arbitration must be allowed to continue into the data portion, repeated start or stop conditions. sda scl sen sda sampled low before sda goes low before the sen bit is set. s bit and sspif set because ssp module reset into idle state. sen cleared automatically because of bus collision. s bit and sspif set because set sen, enable start condition if sda = 1 , scl = 1 sda = 0 , scl = 1 . bclif s sspif sda = 0 , scl = 1 . sspif and bclif are cleared in software sspif and bclif are cleared in software set bclif, start condition. set bclif.
? 2004 microchip technology inc. preliminary ds39625b-page 223 pic18f2585/2680/4585/4680 figure 17-27: bus collision d uring start condition (scl = 0 ) figure 17-28: brg reset due to sda arbitrat ion during start condition sda scl sen bus collision occurs. set bclif. scl = 0 before sda = 0 , set sen, enable start sequence if sda = 1 , scl = 1 t brg t brg sda = 0 , scl = 1 bclif s sspif interrupt cleared in software bus collision occurs. set bclif. scl = 0 before brg time-out, ? 0 ?? 0 ? ? 0 ? ? 0 ? sda scl sen set s less than t brg t brg sda = 0 , scl = 1 bclif s sspif s interrupts cleared in software set sspif sda = 0 , scl = 1 , sda pulled low by other master. reset brg and assert sda. scl pulled low after brg time-out set sspif ? 0 ? set sen, enable start sequence if sda = 1 , scl = 1
pic18f2585/2680/4585/4680 ds39625b-page 224 preliminary ? 2004 microchip technology inc. 17.4.17.2 bus collision during a repeated start condition during a repeated start condition, a bus collision occurs if: a) a low level is sampled on sda when scl goes from low level to high level. b) scl goes low before sda is asserted low, indicating that another master is attempting to transmit a data ? 1 ?. when the user deasserts sda and the pin is allowed to float high, the brg is loaded with sspadd<6:0> and counts down to 0. the scl pin is then deasserted and when sampled high, the sda pin is sampled. if sda is low, a bus collision has occurred (i.e., another master is attempting to transmit a data ? 0 ?, figure 17-29). if sda is sampled high, the brg is reloaded and begins counting. if sda goes from high to low before the brg times out, no bus collision occurs because no two masters can assert sda at exactly the same time. if scl goes from high to low before the brg times out and sda has not already been asserted, a bus collision occurs. in this case, another master is attempting to transmit a data ? 1 ? during the repeated start condition, see figure 17-30. if, at the end of the brg time-out, both scl and sda are still high, the sda pin is driven low and the brg is reloaded and begins counting. at the end of the count, regardless of the status of the scl pin, the scl pin is driven low and the repeated start condition is complete. figure 17-29: bus collision during a repeat ed start condition (case 1) figure 17-30: bus collision during a repe ated start condition (case 2) sda scl rsen bclif s sspif sample sda when scl goes high. if sda = 0 , set bclif and release sda and scl. cleared in software ? 0 ? ? 0 ? sda scl bclif rsen s sspif interrupt cleared in software scl goes low before sda, set bclif. release sda and scl. t brg t brg ? 0 ?
? 2004 microchip technology inc. preliminary ds39625b-page 225 pic18f2585/2680/4585/4680 17.4.17.3 bus collision during a stop condition bus collision occurs during a stop condition if: a) after the sda pin has been deasserted and allowed to float high, sda is sampled low after the brg has timed out. b) after the scl pin is deasserted, scl is sampled low before sda goes high. the stop condition begins with sda asserted low. when sda is sampled low, the scl pin is allowed to float. when the pin is sampled high (clock arbitration), the baud rate generator is loaded with sspadd<6:0> and counts down to 0. after the brg times out, sda is sampled. if sda is sampled low, a bus collision has occurred. this is due to another master attempting to drive a data ? 0 ? (figure 17-31). if the scl pin is sampled low before sda is allowed to float high, a bus collision occurs. this is another case of another master attempting to drive a data ? 0 ? (figure 17-32). figure 17-31: bus collision during a stop condition (case 1) figure 17-32: bus collision during a stop condition (case 2) sda scl bclif pen p sspif t brg t brg t brg sda asserted low sda sampled low after t brg , set bclif ? 0 ? ? 0 ? sda scl bclif pen p sspif t brg t brg t brg assert sda scl goes low before sda goes high, set bclif ? 0 ? ? 0 ?
pic18f2585/2680/4585/4680 ds39625b-page 226 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 227 pic18f2585/2680/4585/4680 18.0 enhanced universal synchronous receiver transmitter (eusart) the universal synchronous asynchronous receiver transmitter (usart) module is one of the two serial i/o modules. (usart is also known as a serial communications interface or sci.) the usart can be configured as a full-duplex asynchronous system that can communicate with peripheral devices, such as crt terminals and personal computers. it can also be configured as a half-duplex synchronous system that can communicate with peripheral devices, such as a/d or d/a integrated circuits, serial eeproms and so on. the eusart module implements additional features, including automatic baud rate detection and calibra- tion, automatic wake-up on sync break reception and 12-bit break character transmit. these make it ideally suited for use in local interconnect network bus (lin bus) systems. the eusart can be configured in the following modes:  asynchronous (full-duplex) with: - auto-wake-up on character reception - auto-baud calibration - 12-bit break character transmission  synchronous ? master (half-duplex) with selectable clock polarity  synchronous ? slave (half-duplex) with selectable clock polarity the pins of the enhanced usart are multiplexed with portc. in order to configure rc6/tx/ck and rc7/rx/dt as a usart:  bit spen (rcsta<7>) must be set (= 1 )  bit trisc<7> must be set (= 1 )  bit trisc<6> must be cleared (= 0 ) for asynchronous and synchronous master modes, or set (= 1 ) for synchronous slave mode the operation of the enhanced usart module is controlled through three registers:  transmit status and control (txsta)  receive status and control (rcsta)  baud rate control (baudcon) these are detailed on the following pages in register 18-1, register 18-2 and register 18-3, respectively. note: the eusart control will automatically reconfigure the pin from input to output as needed.
pic18f2585/2680/4585/4680 ds39625b-page 228 preliminary ? 2004 microchip technology inc. register 18-1: txsta: transmit status and control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-1 r/w-0 csrc tx9 txen sync sendb brgh trmt tx9d bit 7 bit 0 bit 7 csrc: clock source select bit asynchronous mode: don?t care. synchronous mode: 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9: 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen: transmit enable bit 1 = transmit enabled 0 = transmit disabled note: sren/cren overrides txen in sync mode. bit 4 sync: eusart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 sendb: send break character bit asynchronous mode: 1 = send sync break on next transmission (cleared by hardware upon completion) 0 = sync break transmission completed synchronous mode: don?t care. bit 2 brgh: high baud rate select bit asynchronous mode: 1 = high speed 0 = low speed synchronous mode: unused in this mode. bit 1 trmt: transmit shift register status bit 1 = tsr empty 0 = tsr full bit 0 tx9d: 9th bit of transmit data can be address/data bit or a parity bit. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 229 pic18f2585/2680/4585/4680 register 18-2: rcsta: receive status and control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren adden ferr oerr rx9d bit 7 bit 0 bit 7 spen: serial port enable bit 1 = serial port enabled (configures rx/dt and tx/ck pins as serial port pins) 0 = serial port disabled (held in reset) bit 6 rx9: 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren: single receive enable bit asynchronous mode : don?t care. synchronous mode ? master: 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode ? slave: don?t care. bit 4 cren: continuous receive enable bit asynchronous mode: 1 = enables receiver 0 = disables receiver synchronous mode: 1 = enables continuous receive until enable bit cren is cleared (cren overrides sren) 0 = disables continuous receive bit 3 adden: address detect enable bit asynchronous mode 9-bit (rx9 = 1 ) : 1 = enables address detection, enables interrupt and loads the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received and ninth bit can be used as parity bit asynchronous mode 9-bit (rx9 = 0 ) : don?t care. bit 2 ferr: framing error bit 1 = framing error (can be updated by reading rcreg register and receiving next valid byte) 0 = no framing error bit 1 oerr: overrun error bit 1 = overrun error (can be cleared by clearing bit cren) 0 = no overrun error bit 0 rx9d: 9th bit of received data bit this can be address/data bit or a parity bit and must be calculated by user firmware. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 230 preliminary ? 2004 microchip technology inc. register 18-3: baudcon: baud rat e control register r/w-0 r-1 u-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 abdovf rcidl ? sckp brg16 ? wue abden bit 7 bit 0 bit 7 abdovf: auto-baud acquisition rollover status bit 1 = a brg rollover has occurred during auto-baud rate detect mode (must be cleared in software) 0 = no brg rollover has occurred bit 6 rcidl: receive operation idle status bit 1 = receive operation is idle 0 = receive operation is active bit 5 unimplemented: read as ? 0 ? bit 4 sckp: synchronous clock polarity select bit asynchronous mode: unused in this mode. synchronous mode: 1 = idle state for clock (ck) is a high level 0 = idle state for clock (ck) is a low level bit 3 brg16: 16-bit baud rate register enable bit 1 = 16-bit baud rate generator ? spbrgh and spbrg 0 = 8-bit baud rate generator ? spbrg only (compatible mode), spbrgh value ignored bit 2 unimplemented: read as ? 0 ? bit 1 wue: wake-up enable bit asynchronous mode: 1 = eusart will continue to sample the rx pin ? interrupt generated on falling edge; bit cleared in hardware on following rising edge 0 = rx pin not monitored or rising edge detected synchronous mode: unused in this mode. bit 0 abden : auto-baud detect enable bit asynchronous mode: 1 = enable baud rate measurement on the next character. requires reception of a sync field (55h); cleared in hardware upon completion 0 = baud rate measurement disabled or completed synchronous mode: unused in this mode. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 231 pic18f2585/2680/4585/4680 18.1 baud rate generator (brg) the brg is a dedicated 8-bit or 16-bit generator that supports both the asynchronous and synchronous modes of the eusart. by default, the brg operates in 8-bit mode; setting the brg16 bit (baudcon<3>) selects 16-bit mode. the spbrgh:spbrg register pair controls the period of a free running timer. in asynchronous mode, bits brgh (txsta<2>) and brg16 (baudcon<3>) also control the baud rate. in synchronous mode, brgh is ignored. table 18-1 shows the formula for computation of the baud rate for different eusart modes which only apply in master mode (internally generated clock). given the desired baud rate and f osc , the nearest integer value for the spbrgh:spbrg registers can be calculated using the formulas in table 18-1. from this, the error in baud rate can be determined. an example calculation is shown in example 18-1. typical baud rates and error values for the various asynchronous modes are shown in table 18-2. it may be advanta- geous to use the high baud rate (brgh = 1 ) or the 16-bit brg to reduce the baud rate error, or achieve a slow baud rate for a fast oscillator frequency. writing a new value to the spbrgh:spbrg registers causes the brg timer to be reset (or cleared). this ensures the brg does not wait for a timer overflow before outputting the new baud rate. 18.1.1 operation in power managed modes the device clock is used to generate the desired baud rate. when one of the power managed modes is entered, the new clock source may be operating at a different frequency. this may require an adjustment to the value in the spbrg register pair. 18.1.2 sampling the data on the rx pin is sampled three times by a majority detect circuit to determine if a high or a low level is present at the rx pin. table 18-1: baud rate formulas example 18-1: calculating baud rate error table 18-2: registers associated with baud rate generator configuration bits brg/eusart mode baud rate formula sync brg16 brgh 000 8-bit/asynchronous f osc /[64 (n + 1)] 001 8-bit/asynchronous f osc /[16 (n + 1)] 010 16-bit/asynchronous 011 16-bit/asynchronous f osc /[4 (n + 1)] 10x 8-bit/synchronous 11x 16-bit/synchronous legend: x = don?t care, n = value of spbrgh:spbrg register pair name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page txsta csrc tx9 txen sync sendb brgh trmt tx9d 51 rcsta spen rx9 sren cren adden ferr oerr rx9d 51 baudcon abdovf rcidl ? sckp brg16 ? wue abden 51 spbrgh eusart baud rate generator register high byte 51 spbrg eusart baud rate generator register low byte 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the brg. for a device with f osc of 16 mhz, desired baud rate of 9600, asynchronous mode, 8-bit brg: desired baud rate = f osc /(64 ([spbrgh:spbrg] + 1) solving for spbrgh:spbrg: x = ((f osc /desired baud rate)/64) ? 1 = ((16000000/9600)/64) ? 1 = [25.042] = 25 calculated baud rate = 16000000/(64 (25 + 1)) = 9615 error = (calculated baud rate ? desi red baud rate)/de sired baud rate = (9615 ? 9600)/9600 = 0.16%
pic18f2585/2680/4585/4680 ds39625b-page 232 preliminary ? 2004 microchip technology inc. table 18-3: baud rates for asynchronous modes baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3???????????? 1.2 ? ? ? 1.221 1.73 255 1.202 0.16 129 1201 -0.16 103 2.4 2.441 1.73 255 2.404 0.16 129 2.404 0.16 64 2403 -0.16 51 9.6 9.615 0.16 64 9.766 1.73 31 9.766 1.73 15 9615 -0.16 12 19.2 19.531 1.73 31 19.531 1.73 15 19.531 1.73 7 ? ? ? 57.6 56.818 -1.36 10 62.500 8.51 4 52.083 -9.58 2 ? ? ? 115.2 125.000 8.51 4 104.167 -9.58 2 78.125 -32.18 1 ? ? ? baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.16 207 300 -0.16 103 300 -0.16 51 1.2 1.202 0.16 51 1201 -0.16 25 1201 -0.16 12 2.4 2.404 0.16 25 2403 -0.16 12 ? ? ? 9.6 8.929 -6.99 6 ? ? ? ? ? ? 19.2 20.833 8.51 2 ? ? ? ? ? ? 57.6 62.500 8.51 0 ? ? ? ? ? ? 115.2 62.500 -45.75 0 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3???????????? 1.2???????????? 2.4 ? ? ? ? ? ? 2.441 1.73 255 2403 -0.16 207 9.6 9.766 1.73 255 9.615 0.16 129 9.615 0.16 64 9615 -0.16 51 19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19230 -0.16 25 57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55555 3.55 8 115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 ? ? ? ? ? ? 300 -0.16 207 1.2 1.202 0.16 207 1201 -0.16 103 1201 -0.16 51 2.4 2.404 0.16 103 2403 -0.16 51 2403 -0.16 25 9.6 9.615 0.16 25 9615 -0.16 12 ? ? ? 19.2 19.231 0.16 12 ? ? ? ? ? ? 57.6 62.500 8.51 3 ? ? ? ? ? ? 115.2 125.000 8.51 1 ? ? ? ? ? ?
? 2004 microchip technology inc. preliminary ds39625b-page 233 pic18f2585/2680/4585/4680 baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 8332 0.300 0.02 4165 0.300 0.02 2082 300 -0.04 1665 1.2 1.200 0.02 2082 1.200 -0.03 1041 1.200 -0.03 520 1201 -0.16 415 2.4 2.402 0.06 1040 2.399 -0.03 520 2.404 0.16 259 2403 -0.16 207 9.6 9.615 0.16 259 9.615 0.16 129 9.615 0.16 64 9615 -0.16 51 19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19230 -0.16 25 57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55555 3.55 8 115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 ? ? ? baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.04 832 300 -0.16 415 300 -0.16 207 1.2 1.202 0.16 207 1201 -0.16 103 1201 -0.16 51 2.4 2.404 0.16 103 2403 -0.16 51 2403 -0.16 25 9.6 9.615 0.16 25 9615 -0.16 12 ? ? ? 19.2 19.231 0.16 12 ? ? ? ? ? ? 57.6 62.500 8.51 3 ? ? ? ? ? ? 115.2 125.000 8.51 1 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 33332 0.300 0.00 16665 0.300 0.00 8332 300 -0.01 6665 1.2 1.200 0.00 8332 1.200 0.02 4165 1.200 0.02 2082 1200 -0.04 1665 2.4 2.400 0.02 4165 2.400 0.02 2082 2.402 0.06 1040 2400 -0.04 832 9.6 9.606 0.06 1040 9.596 -0.03 520 9.615 0.16 259 9615 -0.16 207 19.2 19.193 -0.03 520 19.231 0.16 259 19.231 0.16 129 19230 -0.16 103 57.6 57.803 0.35 172 57.471 -0.22 86 58.140 0.94 42 57142 0.79 34 115.2 114.943 -0.22 86 116.279 0.94 42 113.636 -1.36 21 117647 -2.12 16 baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.01 3332 300 -0.04 1665 300 -0.04 832 1.2 1.200 0.04 832 1201 -0.16 415 1201 -0.16 207 2.4 2.404 0.16 415 2403 -0.16 207 2403 -0.16 103 9.6 9.615 0.16 103 9615 -0.16 51 9615 -0.16 25 19.2 19.231 0.16 51 19230 -0.16 25 19230 -0.16 12 57.6 58.824 2.12 16 55555 3.55 8 ? ? ? 115.2 111.111 -3.55 8 ? ? ? ? ? ? table 18-3: baud rates for asynchronous modes (continued)
pic18f2585/2680/4585/4680 ds39625b-page 234 preliminary ? 2004 microchip technology inc. 18.1.3 auto-baud rate detect the enhanced usart module supports the automatic detection and calibration of baud rate. this feature is active only in asynchronous mode and while the wue bit is clear. the automatic baud rate measurement sequence (figure 18-1) begins whenever a start bit is received and the abden bit is set. the calculation is self-averaging. in the auto-baud rate detect (abd) mode, the clock to the brg is reversed. rather than the brg clocking the incoming rx signal, the rx signal is timing the brg. in abd mode, the internal baud rate generator is used as a counter to time the bit period of the incoming serial byte stream. once the abden bit is set, the state machine will clear the brg and look for a start bit. the auto-baud rate detection must receive a byte with the value 55h (ascii ?u?, which is also the lin bus sync character) in order to calculate the proper bit rate. the measure- ment is taken over both a low and a high bit time in order to minimize any effects caused by asymmetry of the incoming signal. after a start bit, the spbrg begins counting up, using the preselected clock source on the first rising edge of rx. after eight bits on the rx pin or the fifth rising edge, an accumulated value totalling the proper brg period is left in the spbrgh:spbrg register pair. once the 5th edge is seen (this should correspond to the stop bit), the abden bit is automatically cleared. if a rollover of the brg occurs (an overflow from ffffh to 0000h), the event is trapped by the abdovf status bit (baudcon<7>). it is set in hardware by brg rollovers and can be set or cleared by the user in software. abd mode remains active after rollover events and the abden bit remains set (figure 18-2). while calibrating the baud rate period, the brg registers are clocked at 1/8th the preconfigured clock rate. note that the brg clock will be configured by the brg16 and brgh bits. independent of the brg16 bit setting, both the spbrg and spbrgh will be used as a 16-bit counter. this allows the user to verify that no carry occurred for 8-bit modes by checking for 00h in the spbrgh register. refer to table 18-4 for counter clock rates to the brg. while the abd sequence takes place, the eusart state machine is held in idle. the rcif interrupt is set once the fifth rising edge on rx is detected. the value in the rcreg needs to be read to clear the rcif interrupt. the contents of rcreg should be discarded. table 18-4: brg counter clock rates 18.1.3.1 abd and eusart transmission since the brg clock is reversed during abd acquisi- tion, the eusart transmitter cannot be used during abd. this means that whenever the abden bit is set, txreg cannot be written to. users should also ensure that abden does not become set during a transmit sequence. failing to do this may result in unpredictable eusart operation. note 1: if the wue bit is set with the abden bit, auto-baud rate detection will occur on the byte following the break character. 2: it is up to the user to determine that the incoming character baud rate is within the range of the selected brg clock source. some combinations of oscillator frequency and eusart baud rates are not possible due to bit error rates. overall system timing and communication baud rates must be taken into consideration when using the auto-baud rate detection feature. brg16 brgh brg counter clock 00 f osc /512 01 f osc /128 10 f osc /128 11 f osc /32 note: during the abd sequence, spbrg and spbrgh are both used as a 16-bit counter, independent of the brg16 setting.
? 2004 microchip technology inc. preliminary ds39625b-page 235 pic18f2585/2680/4585/4680 figure 18-1: automatic baud rate calculation figure 18-2: brg overflow sequence brg value rx pin abden bit rcif bit bit 0 bit 1 (interrupt) read rcreg brg clock start auto-cleared set by user xxxxh 0000h edge #1 bit 2 bit 3 edge #2 bit 4 bit 5 edge #3 bit 6 bit 7 edge #4 stop bit edge #5 001ch note: the abd sequence requires the eusart module to be configured in asynchronous mode and wue = 0 . spbrg xxxxh 1ch spbrgh xxxxh 00h start bit 0 xxxxh 0000h 0000h ffffh brg clock abden bit rx pin abdovf bit brg value
pic18f2585/2680/4585/4680 ds39625b-page 236 preliminary ? 2004 microchip technology inc. 18.2 eusart asynchronous mode the asynchronous mode of operation is selected by clearing the sync bit (txsta<4>). in this mode, the eusart uses standard non-return-to-zero (nrz) format (one start bit, eight or nine data bits and one stop bit). the most common data format is 8 bits. an on-chip dedicated 8-bit/16-bit baud rate generator can be used to derive standard baud rate frequencies from the oscillator. the eusart transmits and receives the lsb first. the eusart?s transmitter and receiver are functionally independent but use the same data format and baud rate. the baud rate generator produces a clock, either x16 or x64 of the bit shift rate depending on the brgh and brg16 bits (txsta<2> and baudcon<3>). parity is not supported by the hardware, but can be implemented in software and stored as the 9th data bit. when operating in asynchronous mode, the eusart module consists of the following important elements:  baud rate generator  sampling circuit  asynchronous transmitter  asynchronous receiver  auto-wake-up on sync break character  12-bit break character transmit  auto-baud rate detection 18.2.1 eusart asynchronous transmitter the eusart transmitter block diagram is shown in figure 18-3. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the stop bit has been transmitted from the previous load. as soon as the stop bit is transmitted, the tsr is loaded with new data from the txreg register (if available). once the txreg register transfers the data to the tsr register (occurs in one t cy ), the txreg register is empty and the txif flag bit (pir1<4>) is set. this interrupt can be enabled or disabled by setting or clearing the interrupt enable bit, txie (pie1<4>). txif will be set regardless of the state of txie; it cannot be cleared in software. txif is also not cleared immediately upon loading txreg, but becomes valid in the second instruction cycle following the load instruction. polling txif immediately following a load of txreg will return invalid results. while txif indicates the status of the txreg register, another bit, trmt (txsta<1>), shows the status of the tsr register. trmt is a read-only bit which is set when the tsr register is empty. no interrupt logic is tied to this bit so the user has to poll this bit in order to determine if the tsr register is empty. to set up an asynchronous transmission: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set transmit bit tx9. can be used as address/data bit. 5. enable the transmission by setting bit txen which will also set bit txif. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. load data to the txreg register (starts transmission). 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 18-3: eusart transmit block diagram note 1: the tsr register is not mapped in data memory so it is not available to the user. 2: flag bit txif is set when enable bit txen is set. txif txie interrupt txen baud rate clk spbrg baud rate generator msb lsb data bus txreg register tsr register (8) 0 tx9 trmt spen tx pin pin buffer and control 8 ? ? ? spbrgh brg16 tx9d
? 2004 microchip technology inc. preliminary ds39625b-page 237 pic18f2585/2680/4585/4680 figure 18-4: asynchronous transmission figure 18-5: asynchronous transmission (back to back) table 18-5: registers associated with asynchronous transmission word 1 word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txreg brg output (shift clock) tx txif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag) 1 t cy (pin) word 1 stop bit transmit shift reg. write to txreg brg output (shift clock) tx txif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 note: this timing diagram shows two consecutive transmissions. 1 t cy 1 t cy (pin) start bit name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir1 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 rcsta spen rx9 sren cren adden ferr oerr rx9d 51 txreg eusart transmit register 51 txsta csrc tx9 txen sync sendb brgh trmt tx9d 51 baudcon abdovf rcidl ? sckp brg16 ? wue abden 51 spbrgh eusart baud rate generator register high byte 51 spbrg eusart baud rate generator register low byte 51 legend: ? = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous transmission. note 1: reserved in pic18f2x8x devices; always maintain these bits clear.
pic18f2585/2680/4585/4680 ds39625b-page 238 preliminary ? 2004 microchip technology inc. 18.2.2 eusart asynchronous receiver the receiver block diagram is shown in figure 18-6. the data is received on the rx pin and drives the data recovery block. the data recovery block is actually a high-speed shifter operating at x16 times the baud rate, whereas the main receive serial shifter operates at the bit rate or at f osc . this mode would typically be used in rs-232 systems. to set up an asynchronous reception: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, set enable bit rcie. 4. if 9-bit reception is desired, set bit rx9. 5. enable the reception by setting bit cren. 6. flag bit rcif will be set when reception is complete and an interrupt will be generated if enable bit rcie was set. 7. read the rcsta register to get the 9th bit (if enabled) and determine if any error occurred during reception. 8. read the 8-bit received data by reading the rcreg register. 9. if any error occurred, clear the error by clearing enable bit cren. 10. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. 18.2.3 setting up 9-bit mode with address detect this mode would typically be used in rs-485 systems. to set up an asynchronous reception with address detect enable: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing the sync bit and setting the spen bit. 3. if interrupts are required, set the rcen bit and select the desired priority level with the rcip bit. 4. set the rx9 bit to enable 9-bit reception. 5. set the adden bit to enable address detect. 6. enable reception by setting the cren bit. 7. the rcif bit will be set when reception is complete. the interrupt will be acknowledged if the rcie and gie bits are set. 8. read the rcsta register to determine if any error occurred during reception, as well as read bit 9 of data (if applicable). 9. read rcreg to determine if the device is being addressed. 10. if any error occurred, clear the cren bit. 11. if the device has been addressed, clear the adden bit to allow all received data into the receive buffer and interrupt the cpu. figure 18-6: eusart receiv e block diagram x64 baud rate clk baud rate generator rx pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 64 16 or stop start (8) 7 1 0 rx9 ? ? ? spbrg spbrgh brg16 or 4
? 2004 microchip technology inc. preliminary ds39625b-page 239 pic18f2585/2680/4585/4680 figure 18-7: asynchronous reception table 18-6: registers associated with asynchronous reception start bit bit 7/8 bit 1 bit 0 bit 7/8 bit 0 stop bit start bit start bit bit 7/8 stop bit rx (pin) rcv buffer reg rcv shift reg read rcv buffer reg rcreg rcif (interrupt flag) oerr bit cren word 1 rcreg word 2 rcreg stop bit note: this timing diagram shows three words appearing on the rx input. the rcreg (receive buffer) is read after the third word causing the oerr (overrun) bit to be set. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir1 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 rcsta spen rx9 sren cren adden ferr oerr rx9d 51 rcreg eusart receive register 51 txsta csrc tx9 txen sync sendb brgh trmt tx9d 51 baudcon abdovf rcidl ? sckp brg16 ? wue abden 51 spbrgh eusart baud rate generator register high byte 51 spbrg eusart baud rate generator register low byte 51 legend: ? = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous reception. note 1: reserved in pic18f2x8x devices; always maintain these bits clear.
pic18f2585/2680/4585/4680 ds39625b-page 240 preliminary ? 2004 microchip technology inc. 18.2.4 auto-wake-up on sync break character during sleep mode, all clocks to the eusart are suspended. because of this, the baud rate generator is inactive and a proper byte reception cannot be performed. the auto-wake-up feature allows the controller to wake-up due to activity on the rx/dt line while the eusart is operating in asynchronous mode. the auto-wake-up feature is enabled by setting the wue bit (baudcon<1>). once set, the typical receive sequence on rx/dt is disabled and the eusart remains in an idle state, monitoring for a wake-up event independent of the cpu mode. a wake-up event consists of a high-to-low transition on the rx/dt line. (this coincides with the start of a sync break or a wake-up signal character for the lin protocol.) following a wake-up event, the module generates an rcif interrupt. the interrupt is generated synchro- nously to the q clocks in normal operating modes (figure 18-8) and asynchronously, if the device is in sleep mode (figure 18-9). the interrupt condition is cleared by reading the rcreg register. the wue bit is automatically cleared once a low-to-high transition is observed on the rx line following the wake-up event. at this point, the eusart module is in idle mode and returns to normal operation. this signals to the user that the sync break event is over. 18.2.4.1 special considerations using auto-wake-up since auto-wake-up functions by sensing rising edge transitions on rx/dt, information with any state changes before the stop bit may signal a false end-of-character and cause data or framing errors. to work properly, therefore, the initial character in the trans- mission must be all ? 0 ?s. this can be 00h (8 bytes) for standard rs-232 devices or 000h (12 bits) for lin bus. oscillator start-up time must also be considered, especially in applications using oscillators with longer start-up intervals (i.e., xt or hs mode). the sync break (or wake-up signal) character must be of sufficient length and be followed by a sufficient interval to allow enough time for the selected oscillator to start and provide proper initialization of the eusart. 18.2.4.2 special considerations using the wue bit the timing of wue and rcif events may cause some confusion when it comes to determining the validity of received data. as noted, setting the wue bit places the eusart in an idle mode. the wake-up event causes a receive interrupt by setting the rcif bit. the wue bit is cleared after this when a rising edge is seen on rx/dt. the interrupt condition is then cleared by reading the rcreg register. ordinarily, the data in rcreg will be dummy data and should be discarded. the fact that the wue bit has been cleared (or is still set) and the rcif flag is set should not be used as an indicator of the integrity of the data in rcreg. users should consider implementing a parallel method in firmware to verify received data integrity. to assure that no actual data is lost, check the rcidl bit to verify that a receive operation is not in process. if a receive operation is not occurring, the wue bit may then be set just prior to entering the sleep mode. figure 18-8: auto-wake-up bit (wue) timings during normal operation figure 18-9: auto-wake-up bit (wue) timings during sleep q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit (1) rx/dt line rcif note 1: the eusart remains in idle while the wue bit is set. bit set by user auto-cleared cleared due to user read of rcreg q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit (2) rx/dt line rcif sleep command executed note 1: if the wake-up event requires long oscillator warm-up time, the auto-clear of the wue bit can occur while the stposc signal is still active. this sequence should not depend on the presence of q clocks. 2: the eusart remains in idle while the wue bit is set. sleep ends auto-cleared note 1 cleared due to user read of rcreg bit set by user
? 2004 microchip technology inc. preliminary ds39625b-page 241 pic18f2585/2680/4585/4680 18.2.5 break character sequence the enhanced eusart module has the capability of sending the special break character sequences that are required by the lin bus standard. the break char- acter transmit consists of a start bit, followed by twelve ? 0 ? bits and a stop bit. the frame break character is sent whenever the sendb and txen bits (txsta<3> and txsta<5>) are set while the transmit shift register is loaded with data. note that the value of data written to txreg will be ignored and all ? 0 ?s will be transmitted. the sendb bit is automatically reset by hardware after the corresponding stop bit is sent. this allows the user to preload the transmit fifo with the next transmit byte following the break character (typically, the sync character in the lin specification). note that the data value written to the txreg for the break character is ignored. the write simply serves the purpose of initiating the proper sequence. the trmt bit indicates when the transmit operation is active or idle, just as it does during normal transmis- sion. see figure 18-10 for the timing of the break character sequence. 18.2.5.1 break and sync transmit sequence the following sequence will send a message frame header made up of a break, followed by an auto-baud sync byte. this sequence is typical of a lin bus master. 1. configure the eusart for the desired mode. 2. set the txen and sendb bits to set up the break character. 3. load the txreg with a dummy character to initiate transmission (the value is ignored). 4. write ?55h? to txreg to load the sync character into the transmit fifo buffer. 5. after the break has been sent, the sendb bit is reset by hardware. the sync character now transmits in the preconfigured mode. when the txreg becomes empty, as indicated by the txif, the next data byte can be written to txreg. 18.2.6 receiving a break character the enhanced usart module can receive a break character in two ways. the first method forces configuration of the baud rate at a frequency of 9/13 the typical speed. this allows for the stop bit transition to be at the correct sampling location (13 bits for break versus start bit and 8 data bits for typical data). the second method uses the auto-wake-up feature described in section 18.2.4 ?auto-wake-up on sync break character? . by enabling this feature, the eusart will sample the next two transitions on rx/dt, cause an rcif interrupt and receive the next data byte followed by another interrupt. note that following a break character, the user will typically want to enable the auto-baud rate detect feature. for both methods, the user can set the abd bit once the txif interrupt is observed. figure 18-10: send break character sequence write to txreg brg output (shift clock) start bit bit 0 bit 1 bit 11 stop bit break txif bit (transmit buffer reg. empty flag) tx (pin) trmt bit (transmit shift reg. empty flag) sendb (transmit shift reg. empty flag) sendb sampled here auto-cleared dummy write
pic18f2585/2680/4585/4680 ds39625b-page 242 preliminary ? 2004 microchip technology inc. 18.3 eusart synchronous master mode the synchronous master mode is entered by setting the csrc bit (txsta<7>). in this mode, the data is transmitted in a half-duplex manner (i.e., transmission and reception do not occur at the same time). when transmitting data, the reception is inhibited and vice versa. synchronous mode is entered by setting bit sync (txsta<4>). in addition, enable bit spen (rcsta<7>) is set in order to configure the tx and rx pins to ck (clock) and dt (data) lines, respectively. the master mode indicates that the processor trans- mits the master clock on the ck line. clock polarity is selected with the sckp bit (baudcon<4>); setting sckp sets the idle state on ck as high, while clearing the bit sets the idle state as low. this option is provided to support microwire devices with this module. 18.3.1 eusart synchronous master transmission the eusart transmitter block diagram is shown in figure 18-3. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the last bit has been transmitted from the previous load. as soon as the last bit is transmitted, the tsr is loaded with new data from the txreg (if available). once the txreg register transfers the data to the tsr register (occurs in one t cycle ), the txreg is empty and the txif flag bit (pir1<4>) is set. the interrupt can be enabled or disabled by setting or clearing the inter- rupt enable bit, txie (pie1<4>). txif is set regardless of the state of enable bit txie; it cannot be cleared in software. it will reset only when new data is loaded into the txreg register. while flag bit txif indicates the status of the txreg register, another bit, trmt (txsta<1>), shows the status of the tsr register. trmt is a read-only bit which is set when the tsr is empty. no interrupt logic is tied to this bit so the user has to poll this bit in order to determine if the tsr register is empty. the tsr is not mapped in data memory so it is not available to the user. to set up a synchronous master transmission: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brg16 bit, as required, to achieve the desired baud rate. 2. enable the synchronous master serial port by setting bits sync spen and csrc. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set bit tx9. 5. enable the transmission by setting bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txreg register. 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 18-11: synchronous transmission bit 0 bit 1 bit 7 word 1 q1 q2 q3 q4 q1 q2 q3 q4 q1q2 q3 q4 q1q2 q3 q4 q1 q2 q3 q4 q3 q4 q1 q2 q3 q4 q1q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 bit 2 bit 0 bit 1 bit 7 rc7/rx/dt rc6/tx/ck pin write to txreg reg txif bit (interrupt flag) txen bit ? 1 ? ? 1 ? word 2 trmt bit write word 1 write word 2 note: sync master mode, spbrg = 0 , continuous transmission of two 8-bit words. pin rc6/tx/ck pin (sckp = 0 ) (sckp = 1 )
? 2004 microchip technology inc. preliminary ds39625b-page 243 pic18f2585/2680/4585/4680 figure 18-12: synchronous transmis sion (through txen) table 18-7: registers associated with synchronous master transmission rc7/rx/dt pin rc6/tx/ck pin write to txreg reg txif bit trmt bit bit 0 bit 1 bit 2 bit 6 bit 7 txen bit name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir1 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 rcsta spen rx9 sren cren adden ferr oerr rx9d 51 txreg eusart transmit register 51 txsta csrc tx9 txen sync sendb brgh trmt tx9d 51 baudcon abdovf rcidl ?sckpbrg16 ? wue abden 51 spbrgh eusart baud rate generator register high byte 51 spbrg eusart baud rate generator register low byte 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master transmission. note 1: reserved in pic18f2x8x devices; always maintain these bits clear.
pic18f2585/2680/4585/4680 ds39625b-page 244 preliminary ? 2004 microchip technology inc. 18.3.2 eusart synchronous master reception once synchronous mode is selected, reception is enabled by setting either the single receive enable bit, sren (rcsta<5>), or the continuous receive enable bit, cren (rcsta<4>). data is sampled on the rx pin on the falling edge of the clock. if enable bit sren is set, only a single word is received. if enable bit cren is set, the reception is continuous until cren is cleared. if both bits are set, then cren takes precedence. to set up a synchronous master reception: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brg16 bit, as required, to achieve the desired baud rate. 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. ensure bits cren and sren are clear. 4. if interrupts are desired, set enable bit rcie. 5. if 9-bit reception is desired, set bit rx9. 6. if a single reception is required, set bit sren. for continuous reception, set bit cren. 7. interrupt flag bit rcif will be set when reception is complete and an interrupt will be generated if the enable bit rcie was set. 8. read the rcsta register to get the 9th bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcreg register. 10. if any error occurred, clear the error by clearing bit cren. 11. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 18-13: synchronous reception (master mode, sren) table 18-8: registers associated with synchronous master reception namebit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir1 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 rcsta spen rx9 sren cren adden ferr oerr rx9d 51 rcreg eusart receive register 51 txsta csrc tx9 txen sync sendb brgh trmt tx9d 51 baudcon abdovf rcidl ? sckp brg16 ? wue abden 51 spbrgh eusart baud rate generator register high byte 51 spbrg eusart baud rate generator register low byte 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master reception. note 1: reserved in pic18f2x8x devices; always maintain these bits clear. cren bit rc7/rx/dt rc7/tx/ck pin write to bit sren sren bit rcif bit (interrupt) read rxreg q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q2 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 ? 0 ? bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 ? 0 ? q1 q2 q3 q4 note: timing diagram demonstrates sync master mode with bit sren = 1 and bit brgh = 0 . rc7/tx/ck pin pin (sckp = 0 ) (sckp = 1 )
? 2004 microchip technology inc. preliminary ds39625b-page 245 pic18f2585/2680/4585/4680 18.4 eusart synchronous slave mode synchronous slave mode is entered by clearing bit, csrc (txsta<7>). this mode differs from the synchronous master mode in that the shift clock is sup- plied externally at the ck pin (instead of being supplied internally in master mode). this allows the device to transfer or receive data while in any low-power mode. 18.4.1 eusart synchronous slave transmit the operation of the synchronous master and slave modes are identical, except in the case of the sleep mode. if two words are written to the txreg and then the sleep instruction is executed, the following will occur: a) the first word will immediately transfer to the tsr register and transmit. b) the second word will remain in the txreg register. c) flag bit txif will not be set. d) when the first word has been shifted out of tsr, the txreg register will transfer the second word to the tsr and flag bit txif will now be set. e) if enable bit txie is set, the interrupt will wake the chip from sleep. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave transmission: 1. enable the synchronous slave serial port by setting bits sync and spen and clearing bit csrc. 2. clear bits cren and sren. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set bit tx9. 5. enable the transmission by setting enable bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txregx register. 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. table 18-9: registers associated with synchronous slave transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir1 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 rcsta spen rx9 sren cren adden ferr oerr rx9d 51 txreg eusart transmit register 51 txsta csrc tx9 txen sync sendb brgh trmt tx9d 51 baudcon abdovf rcidl ? sckp brg16 ? wue abden 51 spbrgh eusart baud rate generator register high byte 51 spbrg eusart baud rate generator register low byte 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave transmission. note 1: reserved in pic18f2x8x devices; always maintain these bits clear.
pic18f2585/2680/4585/4680 ds39625b-page 246 preliminary ? 2004 microchip technology inc. 18.4.2 eusart synchronous slave reception the operation of the synchronous master and slave modes is identical, except in the case of sleep or any idle mode and bit sren, which is a ?don?t care? in slave mode. if receive is enabled by setting the cren bit prior to entering sleep or any idle mode, then a word may be received while in this low-power mode. once the word is received, the rsr register will transfer the data to the rcreg register; if the rcie enable bit is set, the inter- rupt generated will wake the chip from the low-power mode. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave reception: 1. enable the synchronous master serial port by setting bits sync and spen and clearing bit csrc. 2. if interrupts are desired, set enable bit rcie. 3. if 9-bit reception is desired, set bit rx9. 4. to enable reception, set enable bit cren. 5. flag bit rcif will be set when reception is complete. an interrupt will be generated if enable bit rcie was set. 6. read the rcsta register to get the 9th bit (if enabled) and determine if any error occurred during reception. 7. read the 8-bit received data by reading the rcreg register. 8. if any error occurred, clear the error by clearing bit cren. 9. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. table 18-10: registers associated with synchronous slave reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir1 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 rcsta spen rx9 sren cren adden ferr oerr rx9d 51 rcreg eusart receive register 51 txsta csrc tx9 txen sync sendb brgh trmt tx9d 51 baudcon abdovf rcidl ?sckpbrg16 ? wue abden 51 spbrgh eusart baud rate generator register high byte 51 spbrg eusart baud rate generator register low byte 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave reception. note 1: reserved in pic18f2x8x devices; always maintain these bits clear.
? 2004 microchip technology inc. preliminary ds39625b-page 247 pic18f2585/2680/4585/4680 19.0 10-bit analog-to-digital converter (a/d) module the analog-to-digital (a/d) converter module has 8 inputs for the pic18f2x8x devices and 11 for the pic18f4x8x devices. this module allows conversion of an analog input signal to a corresponding 10-bit digital number. the module has five registers:  a/d result high register (adresh)  a/d result low register (adresl)  a/d control register 0 (adcon0)  a/d control register 1 (adcon1)  a/d control register 2 (adcon2) the adcon0 register, shown in register 19-1, controls the operation of the a/d module. the adcon1 register, shown in register 19-2, configures the functions of the port pins. the adcon2 register, shown in register 19-3, configures the a/d clock source, programmed acquisition time and justification. register 19-1: adcon0: a/d control register 0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? chs3 chs2 chs1 chs0 go/done adon bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5-2 chs3:chs0: analog channel select bits 0000 = channel 0 (an0) 0001 = channel 1 (an1) 0010 = channel 2 (an2) 0011 = channel 3 (an3) 0100 = channel 4 (an4) 0101 = channel 5 (an5) (1,2) 0110 = channel 6 (an6) (1,2) 0111 = channel 7 (an7) (1,2) 1000 = channel 8 (an8) 1001 = channel 9 (an9) 1010 = channel 10 (an10) 1011 = unused 1100 = unused 1101 = unused 1110 = unused 1111 = unused note 1: these channels are not implemented on pic18f2x8x devices. 2: performing a conversion on unimplemented channels will return full-scale measurements. bit 1 go/done : a/d conversion status bit when adon = 1 : 1 = a/d conversion in progress 0 = a/d idle bit 0 adon: a/d on bit 1 = a/d converter module is enabled 0 = a/d converter module is disabled legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 248 preliminary ? 2004 microchip technology inc. register 19-2: adcon1: a/d control register 1 u-0 u-0 r/w-0 r/w-0 r/w-0 (1) r/w-q (1) r/w-q (1) r/w-q (1) ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5 vcfg1: voltage reference configuration bit (v ref - source) 1 = v ref - (an2) 0 = av ss bit 4 vcfg0: voltage reference configuration bit (v ref + source) 1 = v ref + (an3) 0 = av dd bit 3-0 pcfg3:pcfg0: a/d port configuration control bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown a = analog input d = digital i/o note 1: the por value of the pcfg bits depends on the value of the pbaden bit in configuration register 3h. when pbaden = 1 , pcfg<3:0> = 0000 ; when pbaden = 0 , pcfg<3:0> = 0111 . 2: an5 through an7 are available only in pic18f4x8x devices. pcfg3: pcfg0 an10 an9 an8 an7 (2 ) an6 (2 ) an5 (2 ) an4 an3 an2 an1 an0 0000 (1) aaaaaaaaaaa 0001 aaaaaaaaaaa 0010 aaaaaaaaaaa 0011 aaaaaaaaaaa 0100 aaaaaaaaaaa 0101 daaaaaaaaaa 0110 ddaaaaaaaaa 0111 (1) dddaaaaaaaa 1000 ddddaaaaaaa 1001 dddddaaaaaa 1010 ddddddaaaaa 1011 dddddddaaaa 1100 ddddddddaaa 1101 dddddddddaa 1110 dddddddddda 1111 ddddddddddd
? 2004 microchip technology inc. preliminary ds39625b-page 249 pic18f2585/2680/4585/4680 register 19-3: adcon2: a/d control register 2 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adfm ? acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 bit 7 bit 0 bit 7 adfm: a/d result format select bit 1 = right justified 0 = left justified bit 6 unimplemented: read as ? 0 ? bit 5-3 acqt2:acqt0: a/d acquisition time select bits 111 = 20 t ad 110 = 16 t ad 101 = 12 t ad 100 = 8 t ad 011 = 6 t ad 010 = 4 t ad 001 = 2 t ad 000 = 0 t ad (1) bit 2-0 adcs2:adcs0: a/d conversion clock select bits 111 = f rc (clock derived from a/d rc oscillator) (1) 110 = f osc /64 101 = f osc /16 100 = f osc /4 011 = f rc (clock derived from a/d rc oscillator) (1) 010 = f osc /32 001 = f osc /8 000 = f osc /2 note 1: if the a/d f rc clock source is selected, a delay of one t cy (instruction cycle) is added before the a/d clock starts. this allows the sleep instruction to be executed before starting a conversion. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 250 preliminary ? 2004 microchip technology inc. the analog reference voltage is software selectable to either the device?s positive and negative supply voltage (av dd and av ss ), or the voltage level on the ra3/an3/v ref + and ra2/an2/v ref -/cv ref pins. the a/d converter has a unique feature of being able to operate while the device is in sleep mode. to operate in sleep, the a/d conversion clock must be derived from the a/d?s internal rc oscillator. the output of the sample and hold is the input into the converter, which generates the result via successive approximation. a device reset forces all registers to their reset state. this forces the a/d module to be turned off and any conversion in progress is aborted. each port pin associated with the a/d converter can be configured as an analog input, or as a digital i/o. the adresh and adresl registers contain the result of the a/d conversion. when the a/d conversion is com- plete, the result is loaded into the adresh/adresl registers, the go/done bit (adcon0 register) is cleared and a/d interrupt flag bit adif is set. the block diagram of the a/d module is shown in figure 19-1. figure 19-1: a/d block diagram (input voltage) v ain v ref + reference voltage av dd vcfg1:vcfg0 chs3:chs0 an7 (1) an6 (1) an5 (1) an4 an3 an2 an1 an0 0111 0110 0101 0100 0011 0010 0001 0000 10-bit converter v ref - av ss a/d an10 an9 an8 1010 1001 1000 note 1: channels an5 through an7 are not available on pic18f2x8x devices. 2: i/o pins have diode protection to v dd and v ss . 0 x 1 x x 1 x 0
? 2004 microchip technology inc. preliminary ds39625b-page 251 pic18f2585/2680/4585/4680 the value in the adresh/adresl registers is not modified for a power-on reset. the adresh/adresl registers will contain unknown data after a power-on reset. after the a/d module has been configured as desired, the selected channel must be acquired before the con- version is started. the analog input channels must have their corresponding tris bits selected as an input. to determine acquisition time, see section 19.1 ?a/d acquisition requirements? . after this acquisi- tion time has elapsed, the a/d conversion can be started. an acquisition time can be programmed to occur between setting the go/done bit and the actual start of the conversion. the following steps should be followed to perform an a/d conversion: 1. configure the a/d module:  configure analog pins, voltage reference and digital i/o (adcon1)  select a/d input channel (adcon0)  select a/d acquisition time (adcon2)  select a/d conversion clock (adcon2)  turn on a/d module (adcon0) 2. configure a/d interrupt (if desired):  clear adif bit  set adie bit  set gie bit 3. wait the required acquisition time (if required). 4. start conversion:  set go/done bit (adcon0 register) 5. wait for a/d conversion to complete, by either:  polling for the go/done bit to be cleared or  waiting for the a/d interrupt 6. read a/d result registers (adresh:adresl); clear bit adif, if required. 7. for next conversion, go to step 1 or step 2, as required. the a/d conversion time per bit is defined as t ad . a minimum wait of 2 t ad is required before next acquisition starts. figure 19-2: analog input model v ain c pin rs anx 5 pf v dd v t = 0.6v v t = 0.6v i leakage r ic 1k sampling switch ss r ss c hold = 120 pf v ss 6v sampling switch 5v 4v 3v 2v 567891011 (k ? ) v dd 500 na legend: c pin v t i leakage r ic ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch = sample/hold capacitance (from dac) various junctions = sampling switch resistance r ss
pic18f2585/2680/4585/4680 ds39625b-page 252 preliminary ? 2004 microchip technology inc. 19.1 a/d acquisition requirements for the a/d converter to meet its specified accuracy, the charge holding capacitor (c hold ) must be allowed to fully charge to the input channel voltage level. the analog input model is shown in figure 19-2. the source impedance (r s ) and the internal sampling switch (r ss ) impedance directly affect the time required to charge the capacitor c hold . the sampling switch (r ss ) impedance varies over the device voltage (v dd ). the source impedance affects the offset voltage at the analog input (due to pin leakage current). the maximum recommended impedance for analog sources is 2.5 k ? . after the analog input channel is selected (changed), the channel must be sampled for at least the minimum acquisition time before starting a conversion. to calculate the minimum acquisition time, equation 19-1 may be used. this equation assumes that 1/2 lsb error is used (1024 steps for the a/d). the 1/2 lsb error is the maximum error allowed for the a/d to meet its specified resolution. example 19-3 shows the calculation of the minimum required acquisition time t acq . this calculation is based on the following application system assumptions: c hold = 120 pf rs = 2.5 k ? conversion error 1/2 lsb v dd =5v rss = 7 k ? temperature = 50 c (system max.) v hold = 0v @ time = 0 equation 19-1: acquisition time equation 19-2: a/d minimum charging time equation 19-3: calculating the minimum required acquisition time note: when the conversion is started, the holding capacitor is disconnected from the input pin. t acq = amplifier settling time + holding capacitor charging time + temperature coefficient =t amp + t c + t coff v hold = (v ref ? (v ref /2048))  (1 ? e (-tc/c hold (r ic + r ss + r s )) ) or t c = -(c hold )(r ic + r ss + r s ) ln(1/2048) t acq =t amp + t c + t coff t amp =5 s t coff = (temp ? 25 c)(0.05 s/ c) (50 c ? 25 c)(0.05 s/ c) 1.25 s temperature coefficient is only required for temperatures > 25 c. below 25 c, t coff = 0 ms. t c = -(c hold )(r ic + r ss + r s ) ln(1/2047) s -(120 pf) (1 k ? + 7 k ? + 2.5 k ? ) ln(0.0004883) s 9.61 s t acq =5 s + 1.25 s + 9.61 s 12.86 s
? 2004 microchip technology inc. preliminary ds39625b-page 253 pic18f2585/2680/4585/4680 19.2 selecting and configuring automatic acquisition time the adcon2 register allows the user to select an acquisition time that occurs each time the go/done bit is set. when the go/done bit is set, sampling is stopped and a conversion begins. the user is responsible for ensur- ing the required acquisition time has passed between selecting the desired input channel and setting the go/done bit. this occurs when the acqt2:acqt0 bits (adcon2<5:3>) remain in their reset state (? 000 ?) and is compatible with devices that do not offer programmable acquisition times. if desired, the acqt bits can be set to select a programmable acquisition time for the a/d module. when the go/done bit is set, the a/d module continues to sample the input for the selected acquisition time, then automatically begins a conversion. since the acquisition time is programmed, there may be no need to wait for an acquisition time between selecting a channel and setting the go/done bit. in either case, when the conversion is completed, the go/done bit is cleared, the adif flag is set and the a/d begins sampling the currently selected channel again. if an acquisition time is programmed, there is nothing to indicate if the acquisition time has ended or if the conversion has begun. 19.3 selecting the a/d conversion clock the a/d conversion time per bit is defined as t ad . the a/d conversion requires 11 t ad per 10-bit conversion. the source of the a/d conversion clock is software selectable. there are seven possible options for t ad : 2 t osc 4 t osc 8 t osc 16 t osc 32 t osc 64 t osc  internal rc oscillator for correct a/d conversions, the a/d conversion clock (t ad ) must be as short as possible, but greater than the minimum t ad (approximately 2 s, see parameter 130 for more information). table 19-1 shows the resultant t ad times derived from the device operating frequencies and the a/d clock source selected. table 19-1: t ad vs. device operating frequencies ad clock source (t ad ) maximum device frequency operation adcs2:adcs0 pic18fx585/x680 pic18lfx585/x680 (4) 2 t osc 000 1.25 mhz 666 khz 4 t osc 100 2.50 mhz 1.33 mhz 8 t osc 001 5.00 mhz 2.66 mhz 16 t osc 101 10.0 mhz 5.33 mhz 32 t osc 010 20.0 mhz 10.65 mhz 64 t osc 110 40.0 mhz 21.33 mhz rc (3) x11 1.00 mhz (1) 1.00 mhz (2) note 1: the rc source has a typical t ad time of 4 ms. 2: the rc source has a typical t ad time of 6 ms. 3: for device frequencies above 1 mhz, the device must be in sleep for the entire conversion or the a/d accuracy may be out of specification. 4: low-power (pic18lfxxxx) devices only.
pic18f2585/2680/4585/4680 ds39625b-page 254 preliminary ? 2004 microchip technology inc. 19.4 operation in power managed modes the selection of the automatic acquisition time and a/d conversion clock is determined in part, by the clock source and frequency while in a power managed mode. if the a/d is expected to operate while the device is in a power managed mode, the acqt2:acqt0 and adcs2:adcs0 bits in adcon2 should be updated in accordance with the clock source to be used in that mode. after entering the mode, an a/d acquisition or conversion may be started. once started, the device should continue to be clocked by the same clock source until the conversion has been completed. if desired, the device may be placed into the corresponding idle mode during the conversion. if the device clock frequency is less than 1 mhz, the a/d rc clock source should be selected. operation in the sleep mode requires the a/d f rc clock to be selected. if bits acqt2:acqt0 are set to ? 000 ? and a conversion is started, the conversion will be delayed one instruction cycle to allow execution of the sleep instruction and entry to sleep mode. the idlen bit (osccon<7>) must have already been cleared prior to starting the conversion. 19.5 configuring analog port pins the adcon1, trisa, trisb and trise registers all configure the a/d port pins. the port pins needed as analog inputs must have their corresponding tris bits set (input). if the tris bit is cleared (output), the digital output level (v oh or v ol ) will be converted. the a/d operation is independent of the state of the chs3:chs0 bits and the tris bits. note 1: when reading the port register, all pins configured as analog input channels will read as cleared (a low level). pins config- ured as digital inputs will convert an analog input. analog levels on a digitally configured input will be accurately converted. 2: analog levels on any pin defined as a digital input may cause the digital input buffer to consume current out of the device?s specification limits. 3: the pbaden bit in configuration register 3h configures portb pins to reset as analog or digital pins by control- ling how the pcfg0 bits in adcon1 are reset.
? 2004 microchip technology inc. preliminary ds39625b-page 255 pic18f2585/2680/4585/4680 19.6 a/d conversions figure 19-3 shows the operation of the a/d converter after the go bit has been set and the acqt2:acqt0 bits are cleared. a conversion is started after the follow- ing instruction to allow entry into sleep mode before the conversion begins. figure 19-4 shows the operation of the a/d converter after the go bit has been set and the acqt2:acqt0 bits are set to ? 010 ? and selecting a 4 t ad acquisition time before the conversion starts. clearing the go/done bit during a conversion will abort the current conversion. the a/d result register pair will not be updated with the partially completed a/d conversion sample. this means the adresh:adresl registers will continue to contain the value of the last completed conversion (or the last value written to the adresh:adresl registers). after the a/d conversion is completed or aborted, a 2t ad wait is required before the next acquisition can be started. after this wait, acquisition on the selected channel is automatically started. figure 19-3: a/d conversion t ad cycles (acqt<2:0> = 000 , t acq = 0 ) figure 19-4: a/d conversion t ad cycles (acqt<2:0> = 010 , t acq = 4 t ad ) note: the go/done bit should not be set in the same instruction that turns on the a/d. t ad 1 t ad 2 t ad 3 t ad 4 t ad 5 t ad 6 t ad 7 t ad 8 t ad 11 set go bit holding capacitor is disconnected from analog input (typically 100 ns) t ad 9 t ad 10 t cy - t ad adresh:adresl is loaded, go bit is cleared, adif bit is set, holding capacitor is connected to analog input. conversion starts b0 b9 b6 b5 b4 b3 b2 b1 b8 b7 on the following cycle: 1 2 3 4 5 6 7 8 11 set go bit (holding capacitor is disconnected) 9 10 conversion starts 1 2 3 4 (holding capacitor continues acquiring input) t acqt cycles t ad cycles automatic acquisition time b0 b9 b6 b5 b4 b3 b2 b1 b8 b7 adresh:adresl is loaded, go bit is cleared, adif bit is set, holding capacitor is connected to analog input. on the following cycle:
pic18f2585/2680/4585/4680 ds39625b-page 256 preliminary ? 2004 microchip technology inc. 19.7 use of the ccp1 trigger an a/d conversion can be started by the ?special event trigger? of the eccp1 module. this requires that the eccp1m3:eccp1m0 bits (eccp1con<3:0>) be programmed as ? 1011 ? and that the a/d module is enabled (adon bit is set). when the trigger occurs, the go/done bit will be set, starting the a/d acquisition and conversion and the timer1 (or timer3) counter will be reset to zero. timer1 (or timer3) is reset to automat- ically repeat the a/d acquisition period with minimal software overhead (moving adresh/adresl to the desired location). the appropriate analog input channel must be selected and the minimum acquisition period is either timed by the user, or an appropriate t acq time selected before the ?special event trigger? sets the go/done bit (starts a conversion). if the a/d module is not enabled (adon is cleared), the ?special event trigger? will be ignored by the a/d module, but will still reset the timer1 (or timer3) counter. table 19-2: registers associated with a/d operation name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 ipr1 pspip (1) adip rcip txip sspip ccp1ip tmr2ip tmr1ip 52 pir1 pspif (1) adif rcif txif sspif ccp1if tmr2if tmr1if 52 pie1 pspie (1) adie rcie txie sspie ccp1ie tmr2ie tmr1ie 52 ipr2 oscfip cmip (5) ? eeip bclip hlvdip tmr3ip eccp1ip (5) 51 pir2 oscfif cmif (5) ? eeif bclif hlvdif tmr3if eccp1if (5) 51 pie2 oscfie cmie (5) ? eeie bclie hlvdie tmr3ie eccp1ie (5) 52 adresh a/d result register high byte 50 adresl a/d result register low byte 50 adcon0 ? ? chs3 chs2 chs1 chs0 go/done adon 50 adcon1 ? ? vcfg1 vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 50 adcon2 adfm ? acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 50 porta ra7 (2) ra6 (2) ra5 ra4 ra3 ra2 ra1 ra0 52 trisa trisa7 (2) trisa6 (2) porta data direction register 52 portb read portb pins, write latb latch 52 trisb portb data direction register 52 latb portb output data latch 52 porte (4) ? ? ? ?re3 (3) read porte pins, write late (1) 52 trise (4) ibf obf ibov pspmode ? porte data direction 52 late (4) ? ? ? ? ? late2 late1 late0 52 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for a/d conversion. note 1: these bits are unimplemented on pic18f2x8x devices; always maintain these bits clear. 2: these pins may be configured as port pins depending on the oscillator mode selected. 3: re3 port bit is available only as an input pin when the mclre configuration bit is ? 0 ?. 4: these registers are not implemented on pic18f2x8x devices. 5: these bits are available on pic18f4x8x and reserved on pic18f2x8x devices.
? 2004 microchip technology inc. preliminary ds39625b-page 257 pic18f2585/2680/4585/4680 20.0 comparator module the analog comparator module contains two compara- tors that can be configured in a variety of ways. the inputs can be selected from the analog inputs multiplexed with pins ra0 through ra5, as well as the on-chip volt- age reference (see section 21.0 ?comparator voltage reference module? ). the digital outputs (normal or inverted) are available at the pin level and can also be read through the control register. the cmcon register (register 20-1) selects the comparator input and output configuration. block diagrams of the various comparator configurations are shown in figure 20-1. register 20-1: cmcon: comp arator control register r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 c2out c1out c2inv c1inv cis cm2 cm1 cm0 bit 7 bit 0 bit 7 c2out : comparator 2 output bit when c2inv = 0 : 1 = c2 v in + > c2 v in - 0 = c2 v in + < c2 v in - when c2inv = 1 : 1 = c2 v in + < c2 v in - 0 = c2 v in + > c2 v in - bit 6 c1out : comparator 1 output bit when c1inv = 0 : 1 = c1 v in + > c1 v in - 0 = c1 v in + < c1 v in - when c1inv = 1 : 1 = c1 v in + < c1 v in - 0 = c1 v in + > c1 v in - bit 5 c2inv : comparator 2 output inversion bit 1 = c2 output inverted 0 = c2 output not inverted bit 4 c1inv : comparator 1 output inversion bit 1 = c1 output inverted 0 = c1 output not inverted bit 3 cis : comparator input switch bit when cm2:cm0 = 110 : 1 =c1 v in - connects to ra3/an3/v ref + c2 v in - connects to ra2/an2/v ref - 0 =c1 v in - connects to ra0/an0 c2 v in - connects to ra1/an1 bit 2-0 cm2:cm0 : comparator mode bits figure 20-1 shows the comparator modes and the cm2:cm0 bit settings. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 258 preliminary ? 2004 microchip technology inc. 20.1 comparator configuration there are eight modes of operation for the compara- tors, shown in figure 20-1. bits cm2:cm0 of the cmcon register are used to select these modes. the trisa register controls the data direction of the com- parator pins for each mode. if the comparator mode is changed, the comparator output level may not be valid for the specified mode change delay shown in section 27.0 ?electrical characteristics? . figure 20-1: comparator i/o operating modes note: comparator interrupts should be disabled during a comparator mode change; otherwise, a false interrupt may occur. c1 v in - v in + off comparators reset (por default value) a a cm2:cm0 = 000 c2 v in - v in + off a a c1 v in - v in + c1out two independent comparators a a cm2:cm0 = 010 c2 v in - v in + c2out a a c1 v in - v in + c1out two common reference comparators a a cm2:cm0 = 100 c2 v in - v in + c2out a d c2 v in - v in + off one independent comparator with output d d cm2:cm0 = 001 c1 v in - v in + c1out a a c1 v in - v in + off comparators off d d cm2:cm0 = 111 c2 v in - v in + off d d c1 v in - v in + c1out four inputs multiplexed to two comparators a a cm2:cm0 = 110 c2 v in - v in + c2out a a from v ref module cis = 0 cis = 1 cis = 0 cis = 1 c1 v in - v in + c1out two common reference comparators with outputs a a cm2:cm0 = 101 c2 v in - v in + c2out a d a = analog input, port reads zeros always d = digital input cis (cmcon<3>) is the comparator input switch cv ref c1 v in - v in + c1out two independent comparators with outputs a a cm2:cm0 = 011 c2 v in - v in + c2out a a * setting the trisa<5:4> bits will disable the comparator outputs by configuring the pins as inputs. (read as ? 0 ?) (read as ? 0 ?) (read as ? 0 ?) (read as ? 0 ?) (read as ? 0 ?) rd1/psp1/c1in- rd0/psp0/c1in+ rd3/psp3/c2in- rd2/psp2/c2in+ rd1/psp1/c1in- rd0/psp0/c1in+ rd3/psp3/c2in- rd2/psp2/c2in+ rd1/psp1/c1in- rd0/psp0/c1in+ rd3/psp3/c2in- rd2/psp2/c2in+ rd1/psp1/c1in- rd0/psp0/c1in+ rd3/psp3/c2in- rd2/psp2/c2in+ rd1/psp1/c1in- rd0/psp0/c1in+ rd3/psp3/c2in- rd2/psp2/c2in+ rd1/psp1/c1in- rd0/psp0/c1in+ rd3/psp3/c2in- rd2/psp2/c2in+ rd1/psp1/ rd0/psp0/ rd3/psp3/ rd2/psp2/ c2in- c2in+ c1in+ c1in- re1/wr /an6/c1out* re1/wr /an6/c1out* re2/cs /an7/c2out* rd1/psp1/c1in- rd0/psp0/c1in+ rd3/psp3/c2in- rd2/psp2/c2in+ re1/wr /an6/c1out* re2/cs /an7/c2out*
? 2004 microchip technology inc. preliminary ds39625b-page 259 pic18f2585/2680/4585/4680 20.2 comparator operation a single comparator is shown in figure 20-2, along with the relationship between the analog input levels and the digital output. when the analog input at v in + is less than the analog input v in -, the output of the comparator is a digital low level. when the analog input at v in + is greater than the analog input v in -, the output of the comparator is a digital high level. the shaded areas of the output of the comparator in figure 20-2 represent the uncertainty, due to input offsets and response time. 20.3 comparator reference depending on the comparator operating mode, either an external or internal voltage reference may be used. the analog signal present at v in - is compared to the signal at v in + and the digital output of the comparator is adjusted accordingly (figure 20-2). figure 20-2: single comparator 20.3.1 external reference signal when external voltage references are used, the comparator module can be configured to have the com- parators operate from the same or different reference sources. however, threshold detector applications may require the same reference. the reference signal must be between v ss and v dd and can be applied to either pin of the comparator(s). 20.3.2 internal reference signal the comparator module also allows the selection of an internally generated voltage reference from the comparator voltage reference module. this module is described in more detail in section 21.0 ?comparator voltage reference module? . the internal reference is only available in the mode where four inputs are multiplexed to two comparators (cm2:cm0 = 110 ). in this mode, the internal voltage reference is applied to the v in + pin of both comparators. 20.4 comparator response time response time is the minimum time, after selecting a new reference voltage or input source, before the comparator output has a valid level. if the internal reference is changed, the maximum delay of the internal voltage reference must be considered when using the comparator outputs. otherwise, the maximum delay of the comparators should be used (see section 27.0 ?electrical characteristics? ). 20.5 comparator outputs the comparator outputs are read through the cmcon register. these bits are read-only. the comparator outputs may also be directly output to the re1 and re2 i/o pins. when enabled, multiplexors in the output path of the re1 and re2 pins will switch and the output of each pin will be the unsynchronized output of the comparator. the uncertainty of each of the comparators is related to the input offset voltage and the response time given in the specifications. figure 20-3 shows the comparator output block diagram. the trise bits will still function as an output enable/ disable for the re1 and re2 pins while in this mode. the polarity of the comparator outputs can be changed using the c2inv and c1inv bits (cmcon<4:5>). ? + v in + v in - output output v in - v in + note 1: when reading the port register, all pins configured as analog inputs will read as a ? 0 ?. pins configured as digital inputs will convert an analog input according to the schmitt trigger input specification. 2: analog levels on any pin defined as a digital input may cause the input buffer to consume more current than is specified.
pic18f2585/2680/4585/4680 ds39625b-page 260 preliminary ? 2004 microchip technology inc. figure 20-3: comparator output block diagram 20.6 comparator interrupts the comparator interrupt flag is set whenever there is a change in the output value of either comparator. software will need to maintain information about the status of the output bits, as read from cmcon<7:6>, to determine the actual change that occurred. the cmif bit (pir2<6>) is the comparator interrupt flag. the cmif bit must be reset by clearing it. since it is also possible to write a ? 1 ? to this register, a simulated interrupt may be initiated. both the cmie bit (pie2<6>) and the peie bit (intcon<6>) must be set to enable the interrupt. in addition, the gie bit (intcon<7>) must also be set. if any of these bits are clear, the interrupt is not enabled, though the cmif bit will still be set if an interrupt condition occurs. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of cmcon will end the mismatch condition. b) clear flag bit cmif. a mismatch condition will continue to set flag bit cmif. reading cmcon will end the mismatch condition and allow flag bit cmif to be cleared. 20.7 comparator operation during sleep when a comparator is active and the device is placed in sleep mode, the comparator remains active and the interrupt is functional if enabled. this interrupt will wake-up the device from sleep mode, when enabled. while the comparator is powered up, higher sleep currents than shown in the power-down current specification will occur. each operational comparator will consume additional current, as shown in the comparator specifications. to minimize power consumption while in sleep mode, turn off the comparators (cm2:cm0 = 111 ) before entering sleep. if the device wakes up from sleep, the contents of the cmcon register are not affected. 20.8 effects of a reset a device reset forces the cmcon register to its reset state, causing the comparator module to be in the com- parator reset mode (cm2:cm0 = 000) . this ensures that all potential inputs are analog inputs. device current is minimized when analog inputs are present at reset time. the comparators are powered down during the reset interval. dq en to r e 1 o r re2 pin bus data set multiplex cmif bit -+ port pins read cmcon reset from other comparator cxinv dq en cl note: if a change in the cmcon register (c1out or c2out) should occur when a read operation is being executed (start of the q2 cycle), then the cmif (pir registers) interrupt flag may not get set.
? 2004 microchip technology inc. preliminary ds39625b-page 261 pic18f2585/2680/4585/4680 20.9 analog input connection considerations a simplified circuit for an analog input is shown in figure 20-4. since the analog pins are connected to a digital output, they have reverse biased diodes to v dd and v ss . the analog input, therefore, must be between v ss and v dd . if the input voltage deviates from this range by more than 0.6v in either direction, one of the diodes is forward biased and a latch-up condition may occur. a maximum source impedance of 10 k ? is recommended for the analog sources. any external component connected to an analog input pin, such as a capacitor or a zener diode, should have very little leakage current. figure 20-4: comparator analog input model table 20-1: registers associated with comparator module va r s < 10k a in c pin 5 pf v dd v t = 0.6v v t = 0.6v r ic i leakage 500 na v ss legend: c pin = input capacitance v t = threshold voltage i leakage = leakage current at the pin due to various junctions r ic = interconnect resistance r s = source impedance va = analog voltage comparator input name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page cmcon (3) c2out c1out c2inv c1inv cis cm2 cm1 cm0 51 cvrcon (3) cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 51 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 52 ipr2 oscfip cmip (2) ? eeip bclip hlvdip tmr3ip eccp1ip (2) 51 pir2 oscfif cmif (2) ? eeif bclif hlvdif tmr3if eccp1if (2) 51 pie2 oscfie cmie (2) ? eeie bclie hlvdie tmr3ie eccp1ie (2) 52 porta ra7 (1) ra6 (1) ra5 ra4 ra3 ra2 ra1 ra0 52 lata lata7 (1) lata6 (1) lata data output register 52 trisa trisa7 (1) trisa6 (1) porta data direction register 52 legend: ? = unimplemented, read as ? 0 ?. shaded cells are unused by the comparator module. note 1: porta pins are enabled based on oscillator configuration. 2: these bits are available in pic18f4x8x devices and reserved in pic18f2x8x devices. 3: these registers are unimplemented on pic18f2x8x devices.
pic18f2585/2680/4585/4680 ds39625b-page 262 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 263 pic18f2585/2680/4585/4680 21.0 comparator voltage reference module the comparator voltage reference is a 16-tap resistor ladder network that provides a selectable reference voltage. although its primary purpose is to provide a reference for the analog comparators, it may also be used independently of them. a block diagram is of the module shown in figure 21-1. the resistor ladder is segmented to provide two ranges of cv ref values and has a power-down function to conserve power when the reference is not being used. the module?s supply reference can be provided from either device v dd /v ss or an external voltage reference. 21.1 configuring the comparator voltage reference the voltage reference module is controlled through the cvrcon register (register 21-1). the comparator voltage reference provides two ranges of output voltage, each with 16 distinct levels. the range to be used is selected by the cvrr bit (cvrcon<5>). the primary difference between the ranges is the size of the steps selected by the cv ref selection bits (cvr3:cvr0), with one range offering finer resolution. the equations used to calculate the output of the comparator voltage reference are as follows: if cvrr = 1 : cv ref = ((cvr3:cvr0)/24) x cv rsrc if cvrr = 0 : cv ref = (cv dd x 1/4) + (((cvr3:cvr0)/32) x cv rsrc ) the comparator reference supply voltage can come from either v dd and v ss , or the external v ref + and v ref - that are multiplexed with ra2 and ra3. the voltage source is selected by the cvrss bit (cvrcon<4>). the settling time of the comparator voltage reference must be considered when changing the cv ref output (see table 27-3 in section 27.0 ?electrical characteristics? ). register 21-1: cvrcon: comparat or voltage reference control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cvren cvroe (1) cvrr cvrss cvr3 cvr2 cvr1 cvr0 bit 7 bit 0 bit 7 cvren : comparator voltage reference enable bit 1 = cv ref circuit powered on 0 = cv ref circuit powered down bit 6 cvroe : comparator v ref output enable bit (1) 1 = cv ref voltage level is also output on the ra0/an0/cv ref pin 0 = cv ref voltage is disconnected from the ra0/an0/cv ref pin note 1: cvroe overrides the trisa<0> bit setting. if enabled for output, ra2 must also be configured as an input by setting trisa<2> to ? 1 ?. bit 5 cvrr : comparator v ref range selection bit 1 = 0.00 cv rsrc to 0.75 cv rsrc , with cv rsrc /24 step size 0 = 0.25 cv rsrc to 0.75 cv rsrc , with cv rsrc /32 step size bit 4 cvrss : comparator v ref source selection bit 1 = comparator reference source, cv rsrc = (v ref +) ? (v ref -) 0 = comparator reference source, cv rsrc = v dd ? v ss bit 3-0 cvr3:cvr0: comparator v ref value selection bits (0 (cvr3:cvr0) 15) when cvrr = 1 : cv ref = ((cvr3:cvr0)/24) ? (cv rsrc ) when cvrr = 0 : cv ref = (cv rsrc /4) + ((cvr3:cvr0)/32) ? (cv rsrc ) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 264 preliminary ? 2004 microchip technology inc. figure 21-1: comparator voltage reference block diagram 21.2 voltage reference accuracy/error the full range of voltage reference cannot be realized due to the construction of the module. the transistors on the top and bottom of the resistor ladder network (figure 21-1) keep cv ref from approaching the reference source rails. the voltage reference is derived from the reference source; therefore, the cv ref output changes with fluctuations in that source. the tested absolute accuracy of the voltage reference can be found in section 27.0 ?electrical characteristics? . 21.3 operation during sleep when the device wakes up from sleep through an interrupt or a watchdog timer time-out, the contents of the cvrcon register are not affected. to minimize current consumption in sleep mode, the voltage reference should be disabled. 21.4 effects of a reset a device reset disables the voltage reference by clearing bit cvren (cvrcon<7>). this reset also disconnects the reference from the ra0 pin by clearing bit cvroe (cvrcon<6>) and selects the high-voltage range by clearing bit cvrr (cvrcon<5>). the cvr value select bits are also cleared. 21.5 connection considerations the voltage reference module operates independently of the comparator module. the output of the reference generator may be connected to the ra0 pin if the trisa<0> bit and the cvroe bit are both set. enabling the voltage reference output onto the ra0 pin, with an input signal present, will increase current consumption. connecting ra0 as a digital output with cvrss enabled will also increase current consumption. the ra0 pin can be used as a simple d/a output with limited drive capability. due to the limited current drive capability, a buffer must be used on the voltage reference output for external connections to v ref . figure 21-2 shows an example buffering technique. 16 to 1 mux cvr3:cvr0 8r r cvren cvrss = 0 v dd v ref + cvrss = 1 8r cvrss = 0 v ref - cvrss = 1 r r r r r r 16 steps cvrr cv ref
? 2004 microchip technology inc. preliminary ds39625b-page 265 pic18f2585/2680/4585/4680 figure 21-2: voltage reference output buffer example table 21-1: registers associated with comparator voltage reference cv ref output + ? cv ref module voltage reference output impedance r (1) ra2 note 1: r is dependent upon the voltage reference configuration bits, cvrcon<3:0> and cvrcon<5>. pic18f4x8x name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page cvrcon (2) cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 51 cmcon (2) c2out c1out c2inv c1inv cis cm2 cm1 cm0 51 trisa trisa7 (1) trisa6 (1) porta data direction register 52 legend: shaded cells are not used with the comparator voltage reference. note 1: porta pins are enabled based on oscillator configuration. 2: these registers are unimplemented on pic18f2x8x devices.
pic18f2585/2680/4585/4680 ds39625b-page 266 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 267 pic18f2585/2680/4585/4680 22.0 high/low-voltage detect (hlvd) pic18f2585/2680/4585/4680 devices have a high/low-voltage detect module (hlvd). this is a programmable circuit that allows the user to specify both a device voltage trip point and the direction of change from that point. if the device experiences an excursion past the trip point in that direction, an interrupt flag is set. if the interrupt is enabled, the program execution will branch to the interrupt vector address and the software can then respond to the interrupt. the high/low-voltage detect control register (register 22-1) completely controls the operation of the hlvd module. this allows the circuitry to be ?turned off? by the user under software control, which minimizes the current consumption for the device. the block diagram for the hlvd module is shown in figure 22-1. register 22-1: hlvdcon: high/low-voltage de tect control register r/w-0 u-0 r-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-1 vdirmag ? irvst hlvden hlvdl3 (1) hlvdl2 (1) hlvdl1 (1) hlvdl0 (1) bit 7 bit 0 bit 7 vdirmag: voltage direction magnitude select bit 1 = event occurs when voltage equals or exceeds trip point (hlvdl3:hldvl0) 0 = event occurs when voltage equals or falls below trip point (hlvdl3:hlvdl0) bit 6 unimplemented: read as ? 0 ? bit 5 irvst: internal reference voltage stable flag bit 1 = indicates that the voltage detect logic will generate the interrupt flag at the specified voltage range 0 = indicates that the voltage detect logic will not generate the interrupt flag at the specified voltage range and the hlvd interrupt should not be enabled bit 4 hlvden: high/low-voltage detect power enable bit 1 = hlvd enabled 0 = hlvd disabled bit 3-0 hlvdl3:hlvdl0: voltage detection limit bits (1) 1111 = external analog input is used (input comes from the hlvdin pin) 1110 = 4.48v-4.69v 1101 = 4.23v-4.43v 1100 = 4.01v-4.20v 1011 = 3.81v-3.99v 1010 = 3.63v-3.80v 1001 = 3.46v-3.63v 1000 = 3.31v-3.47v 0111 = 3.05v-3.19v 0110 = 2.82v-2.95v 0101 = 2.72v-2.85v 0100 = 2.54v-2.66v 0011 = 2.38v-2.49v 0010 = 2.31v-2.42v 0001 = 2.18v-2.28v 0000 = 2.12v-2.22v note 1: hlvdl3:hlvdl0 modes that result in a trip point below the valid operating voltage of the device are not tested. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 268 preliminary ? 2004 microchip technology inc. the module is enabled by setting the hlvden bit. each time that the hlvd module is enabled, the circuitry requires some time to stabilize. the irvst bit is a read-only bit and is used to indicate when the circuit is stable. the module can only generate an interrupt after the circuit is stable and irvst is set. the vdirmag bit determines the overall operation of the module. when vdirmag is cleared, the module monitors for drops in v dd below a predetermined set point. when the bit is set, the module monitors for rises in v dd above the set point. 22.1 operation when the hlvd module is enabled, a comparator uses an internally generated reference voltage as the set point. the set point is compared with the trip point, where each node in the resistor divider represents a trip point voltage. the ?trip point? voltage is the voltage level at which the device detects a high or low-voltage event, depending on the configuration of the module. when the supply voltage is equal to the trip point, the voltage tapped off of the resistor array is equal to the internal reference voltage generated by the voltage reference module. the comparator then generates an interrupt signal by setting the hlvdif bit. the trip point voltage is software programmable to any one of sixteen values. the trip point is selected by programming the hlvdl3:hlvdl0 bits (hlvdcon<3:0>). the hlvd module has an additional feature that allows the user to supply the trip voltage to the module from an external source. this mode is enabled when bits hlvdl3:hlvdl0 are set to ? 1111 ?. in this state, the comparator input is multiplexed from the external input pin, hlvdin. this gives users flexibility because it allows them to configure the high/low-voltage detect interrupt to occur at any voltage in the valid operating range. figure 22-1: hlvd module block diagram (with external input) set v dd 16 to 1 mux hlvden hlvdcon hlvdin hlvdl3:hlvdl0 register hlvdin v dd externally generated trip point hlvdif hlvden boren internal voltage reference vdirmag
? 2004 microchip technology inc. preliminary ds39625b-page 269 pic18f2585/2680/4585/4680 22.2 hlvd setup the following steps are needed to set up the hlvd module: 1. disable the module by clearing the hlvden bit (hlvdcon<4>). 2. write the value to the hlvdl3:hlvdl0 bits that select the desired hlvd trip point. 3. set the vdirmag bit to detect high voltage (vdirmag = 1 ) or low voltage (vdirmag = 0 ). 4. enable the hlvd module by setting the hlvden bit. 5. clear the hlvd interrupt flag (pir2<2>), which may have been set from a previous interrupt. 6. enable the hlvd interrupt if interrupts are desired by setting the hlvdie and gie bits (pie<2> and intcon<7>). an interrupt will not be generated until the irvst bit is set. 22.3 current consumption when the module is enabled, the hlvd comparator and voltage divider are enabled and will consume static current. the total current consumption, when enabled, is specified in electrical specification parameter d022b. depending on the application, the hlvd module does not need to be operating constantly. to decrease the current requirements, the hlvd circuitry may only need to be enabled for short periods where the voltage is checked. after doing the check, the hlvd module may be disabled. 22.4 hlvd start-up time the internal reference voltage of the hlvd module, specified in electrical specification parameter d420, may be used by other internal circuitry, such as the programmable brown-out reset. if the hlvd or other circuits using the voltage reference are disabled to lower the device?s current consumption, the reference voltage circuit will require time to become stable before a low or high-voltage condition can be reliably detected. this start-up time, t irvst , is an interval that is independent of device clock speed. it is specified in electrical specification parameter 36. the hlvd interrupt flag is not enabled until t irvst has expired and a stable reference voltage is reached. for this reason, brief excursions beyond the set point may not be detected during this interval. refer to figure 22-2 or figure 22-3. figure 22-2: low-voltage detect operation (vdirmag = 0 ) v lvd v dd hlvdif v lvd v dd enable hlvd t ivrst hlvdif may not be set enable hlvd hlvdif hlvdif cleared in software hlvdif cleared in software hlvdif cleared in software, case 1: case 2: hlvdif remains set since hlvd condition still exists t ivrst internal reference is stable internal reference is stable irvst irvst
pic18f2585/2680/4585/4680 ds39625b-page 270 preliminary ? 2004 microchip technology inc. figure 22-3: high-voltage detect operation (vdirmag = 1 ) 22.5 applications in many applications, the ability to detect a drop below, or rise above a particular threshold is desirable. for example, the hlvd module could be periodically enabled to detect universal serial bus (usb) attach or detach. this assumes the device is powered by a lower voltage source than the usb when detached. an attach would indicate a high-voltage detect from, for example, 3.3v to 5v (the voltage on usb) and vice versa for a detach. this feature could save a design a few extra components and an attach signal (input pin). for general battery applications, figure 22-4 shows a possible voltage curve. over time, the device voltage decreases. when the device voltage reaches voltage v a , the hlvd logic generates an interrupt at time t a . the interrupt could cause the execution of an isr, which would allow the application to perform ?house- keeping tasks? and perform a controlled shutdown before the device voltage exits the valid operating range at t b . the hlvd, thus, would give the application a time window, represented by the difference between t a and t b , to safely exit. figure 22-4: typical low-voltage detect application v lvd v dd hlvdif v lvd v dd enable hlvd t ivrst hlvdif may not be set enable hlvd hlvdif hlvdif cleared in software hlvdif cleared in software hlvdif cleared in software, case 1: case 2: hlvdif remains set since hlvd condition still exists t ivrst irvst internal reference is stable internal reference is stable irvst time voltage v a v b t a t b v a = hlvd trip point v b = minimum valid device operating voltage legend:
? 2004 microchip technology inc. preliminary ds39625b-page 271 pic18f2585/2680/4585/4680 22.6 operation during sleep when enabled, the hlvd circuitry continues to operate during sleep. if the device voltage crosses the trip point, the hlvdif bit will be set and the device will wake-up from sleep. device execution will continue from the interrupt vector address if interrupts have been globally enabled. 22.7 effects of a reset a device reset forces all registers to their reset state. this forces the hlvd module to be turned off. table 22-1: registers associated with high/low-voltage detect module name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page hlvdcon vdirmag ? irvst hlvden hlvdl3 hlvdl2 hlvdl1 hlvdl0 50 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 49 pir2 oscfif cmif ? eeif bclif hlvdif tmr3if eccp1if 51 pie2 oscfie cmie ? eeie bclie hlvdie tmr3ie eccp1ie 52 ipr2 oscfip cmip ? eeip bclip hlvdip tmr3ip eccp1ip 51 legend: ? = unimplemented, read as ? 0 ?. shaded cells are unused by the hlvd module.
pic18f2585/2680/4585/4680 ds39625b-page 272 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 273 pic18f2585/2680/4585/4680 23.0 ecan? module pic18f2585/2680/4585/4680 devices contain an enhanced controller area network (ecan) module. the ecan module is fully backward compatible with the can module available in pic18cxx8 and pic18fxx8 devices. the controller area network (can) module is a serial interface which is useful for communicating with other peripherals or microcontroller devices. this interface, or protocol, was designed to allow communications within noisy environments. the ecan module is a communication controller, imple- menting the can 2.0a or b protocol as defined in the bosch specification. the module will support can 1.2, can 2.0a, can 2.0b passive and can 2.0b active versions of the protocol. the module implementation is a full can system; however, the can specification is not covered within this data sheet. refer to the bosch can specification for further details. the module features are as follows:  implementation of the can protocol can 1.2, can 2.0a and can 2.0b  devicenet tm data bytes filter support  standard and extended data frames  0-8 bytes data length  programmable bit rate up to 1 mbit/sec  fully backward compatible with pic18xxx8 can module  three modes of operation: - mode 0 ? legacy mode - mode 1 ? enhanced legacy mode with devicenet support - mode 2 ? fifo mode with devicenet support  support for remote frames with automated handling  double-buffered receiver with two prioritized received message storage buffers  six buffers programmable as rx and tx message buffers  16 full (standard/extended identifier) acceptance filters that can be linked to one of four masks  two full acceptance filter masks that can be assigned to any filter  one full acceptance filter that can be used as either an acceptance filter or acceptance filter mask  three dedicated transmit buffers with application specified prioritization and abort capability  programmable wake-up functionality with integrated low-pass filter  programmable loopback mode supports self-test operation  signaling via interrupt capabilities for all can receiver and transmitter error states  programmable clock source  programmable link to timer module for time-stamping and network synchronization  low-power sleep mode 23.1 module overview the can bus module consists of a protocol engine and message buffering and control. the can protocol engine automatically handles all functions for receiving and transmitting messages on the can bus. messages are transmitted by first loading the appropriate data registers. status and errors can be checked by reading the appropriate registers. any message detected on the can bus is checked for errors and then matched against filters to see if it should be received and stored in one of the two receive registers. the can module supports the following frame types:  standard data frame  extended data frame  remote frame  error frame  overload frame reception  interframe space generation/detection the can module uses the rb2/cantx and rb3/ canrx pins to interface with the can bus. in normal mode, the can module automatically overrides trisb<2>. the user must ensure that trisb<3> is set. 23.1.1 module functionality the can bus module consists of a protocol engine, message buffering and control (see figure 23-1). the protocol engine can best be understood by defining the types of data frames to be transmitted and received by the module. the following sequence illustrates the necessary initial- ization steps before the ecan module can be used to transmit or receive a message. steps can be added or removed depending on the requirements of the application. 1. ensure that the ecan module is in configuration mode. 2. select ecan operational mode. 3. set up the baud rate registers. 4. set up the filter and mask registers. 5. set the ecan module to normal mode or any other mode required by the application logic.
pic18f2585/2680/4585/4680 ds39625b-page 274 preliminary ? 2004 microchip technology inc. figure 23-1: can buffers and protocol engine block diagram msgreq txb2 abtf mloa txerr mtxbuff message message queue control transmit byte sequencer msgreq txb1 abtf mloa txerr mtxbuff message msgreq txb0 abtf mloa txerr mtxbuff message acceptance filters (rxf0-rxf05) a c c e p t data field identifier acceptance mask rxm1 acceptance filters (rxf06-rxf15) m a b acceptance mask rxm0 rcv byte 16 ? 4 to 1 muxs protocol message buffers transmit option mode 0 mode 1, 2 6 tx/rx buffers 2 rx buffers crc<14:0> comparator receive<8:0> transmit<7:0> receive error transmit error protocol rec tec err-pas bus-off finite state machine counter counter shift<14:0> {transmit<5:0>, receive<8:0>} transmit logic bit timing logic tx rx configuration registers clock generator buffers engine mode 0 mode 1, 2 rxf15 v cc
? 2004 microchip technology inc. preliminary ds39625b-page 275 pic18f2585/2680/4585/4680 23.2 can module registers there are many control and data registers associated with the can module. for convenience, their descriptions have been grouped into the following sections:  control and status registers  dedicated transmit buffer registers  dedicated receive buffer registers  programmable tx/rx and auto rtr buffers  baud rate control registers  i/o control register  interrupt status and control registers detailed descriptions of each register and their usage are described in the following sections. 23.2.1 can control and status registers the registers described in this section control the overall operation of the can module and show its operational status. note: not all can registers are available in the access bank.
pic18f2585/2680/4585/4680 ds39625b-page 276 preliminary ? 2004 microchip technology inc. register 23-1: cancon: can control regist er mode 0 r/w-1 r/w-0 r/w-0 r/s-0 r/w-0 r/w-0 r/w-0 u-0 reqop2 reqop1 reqop0 abat win2 win1 win0 ? mode 1 r/w-1 r/w-0 r/w-0 r/s-0 u-0 u-0 u-0 u-0 reqop2 reqop1 reqop0 abat ? ? ? ? mode 2 r/w-1 r/w-0 r/w-0 r/s-0 r-0 r-0 r-0 r-0 reqop2 reqop1 reqop0 abat fp3 fp2 fp1 fp0 bit 7 bit 0 bit 7-5 reqop2:reqop0: request can operation mode bits 1xx = request configuration mode 011 = request listen only mode 010 = request loopback mode 001 = request disable mode 000 = request normal mode bit 4 abat: abort all pending transmissions bit 1 = abort all pending transmissions (in all transmit buffers) 0 = transmissions proceeding as normal bit 3-1 mode 0: win2:win0: window address bits these bits select which of the can buffers to switch into the access bank area. this allows access to the buffer registers from any data memory bank. after a frame has caused an interrupt, the icode3:icode0 bits can be copied to the win3:win0 bits to select the correct buffer. see example 23-2 for a code example. 111 = receive buffer 0 110 = receive buffer 0 101 = receive buffer 1 100 = transmit buffer 0 011 = transmit buffer 1 010 = transmit buffer 2 001 = receive buffer 0 000 = receive buffer 0 bit 0 unimplemented: read as ? 0 ? bit 4-0 mode 1: unimplemented: read as ? 0 ? mode 2: fp3:fp0: fifo read pointer bits these bits point to the message buffer to be read. 0111:0000 = message buffer to be read 1111:1000 = reserved legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 277 pic18f2585/2680/4585/4680 register 23-2: canstat: can status register mode 0 r-1 r-0 r-0 r-0 r-0 r-0 r-0 u-0 opmode2 (1) opmode1 (1) opmode0 (1) ? icode3 icode2 icode1 ? mode 1, 2 r-1 r-0 r-0 r-0 r-0 r-0 r-0 r-0 opmode2 (1) opmode1 (1) opmode0 (1) eicode4 eicode3 eicode2 eicode1 eicode0 bit 7 bit 0 bit 7-5 opmode2:opmode0: operation mode status bits (1) 111 = reserved 110 = reserved 101 = reserved 100 = configuration mode 011 = listen only mode 010 = loopback mode 001 = disable/sleep mode 000 = normal mode bit 4 mode 0: unimplemented: read as ? 0 ? bit 3-1 icode3:icode1: interrupt code bits when an interrupt occurs, a prioritized coded interrupt value will be present in these bits. this code indicates the source of the interrupt. by copying icode3:icode1 to win2:win0 (mode 0) or eicode4:eicode0 to ewin4:ewin0 (mode 1 and 2), it is possible to select the correct buffer to map into the access bank area. see example 23-2 for a code example. to simplify the description, the following table lists all five bits. bit 0 unimplemented: read as ? 0 ? bit 4-0 mode 1, 2: eicode4:eicode0: interrupt code bits see icode3:icode1 above. note 1: to achieve maximum power saving and/or able to wake-up on can bus activity, switch can module in disable mode before putting device to sleep. 2: if buffer is configured as receiver, eicode bits will contain ? 10000 ? upon interrupt. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown mode 0 mode 1 mode 2 no interrupt 00000 00000 00000 error interrupt 00010 00010 00010 txb2 interrupt 00100 00100 00100 txb1 interrupt 00110 00110 00110 txb0 interrupt 01000 01000 01000 rxb1 interrupt 01010 10001 ----- rxb0 interrupt 01100 10000 10000 wake-up interrupt 00010 01110 01110 rxb0 interrupt ----- 10000 10000 rxb1 interrupt ----- 10001 10000 rx/tx b0 interrupt ----- 10010 10010 rx/tx b1 interrupt ----- 10011 10011 (2) rx/tx b2 interrupt ----- 10100 10100 (2) rx/tx b3 interrupt ----- 10101 10101 (2) rx/tx b4 interrupt ----- 10110 10110 (2) rx/tx b5 interrupt ----- 10111 10111 (2)
pic18f2585/2680/4585/4680 ds39625b-page 278 preliminary ? 2004 microchip technology inc. example 23-1: changing to configuration mode example 23-2: win and icode bits usage in interrupt service routine to access tx/rx buffers ; request configuration mode. movlw b?10000000? ; set to configuration mode. movwf cancon ; a request to switch to configuration mode may not be immediately honored. ; module will wait for can bus to be idle before switching to configuration mode. ; request for other modes such as loopback, disable etc. may be honored immediately. ; it is always good practice to wait and verify before continuing. configwait: movf canstat, w ; read current mode state. andlw b?10000000? ; interested in opmode bits only. tstfsz wreg ; is it configuration mode yet? bra configwait ; no. continue to wait... ; module is in configuration mode now. ; modify configuration registers as required. ; switch back to normal mode to be able to communicate. ; save application required context. ; poll interrupt flags and determine source of interrupt ; this was found to be can interrupt ; tempcancon and tempcanstat are variables defined in access bank low movff cancon, tempcancon ; save cancon.win bits ; this is required to prevent cancon ; from corrupting can buffer access ; in-progress while this interrupt ; occurred movff canstat, tempcanstat ; save canstat register ; this is required to make sure that ; we use same canstat value rather ; than one changed by another can ; interrupt. movf tempcanstat, w ; retrieve icode bits andlw b?00001110? addwf pcl, f ; perform computed goto ; to corresponding interrupt cause bra nointerrupt ; 000 = no interrupt bra errorinterrupt ; 001 = error interrupt bra txb2interrupt ; 010 = txb2 interrupt bra txb1interrupt ; 011 = txb1 interrupt bra txb0interrupt ; 100 = txb0 interrupt bra rxb1interrupt ; 101 = rxb1 interrupt bra rxb0interrupt ; 110 = rxb0 interrupt ; 111 = wake-up on interrupt wakeupinterrupt bcf pir3, wakif ; clear the interrupt flag ; ; user code to handle wake-up procedure ; ; ; continue checking for other interrupt source or return from here ? nointerrupt ? ; pc should never vector here. user may ; place a trap such as infinite loop or pin/port ; indication to catch this error.
? 2004 microchip technology inc. preliminary ds39625b-page 279 pic18f2585/2680/4585/4680 example 23-2: win and icode bits usage in interrupt service routine to access tx/rx buffers (continued) errorinterrupt bcf pir3, errif ; clear the interrupt flag ? ; handle error. retfie txb2interrupt bcf pir3, txb2if ; clear the interrupt flag goto accessbuffer txb1interrupt bcf pir3, txb1if ; clear the interrupt flag goto accessbuffer txb0interrupt bcf pir3, txb0if ; clear the interrupt flag goto accessbuffer rxb1interrupt bcf pir3, rxb1if ; clear the interrupt flag goto accessbuffer rxb0interrupt bcf pir3, rxb0if ; clear the interrupt flag goto accessbuffer accessbuffer ; this is either tx or rx interrupt ; copy canstat.icode bits to cancon.win bits movf tempcancon, w ; clear cancon.win bits before copying ; new ones. andlw b?11110001? ; use previously saved cancon value to ; make sure same value. movwf tempcancon ; copy masked value back to tempcancon movf tempcanstat, w ; retrieve icode bits andlw b?00001110? ; use previously saved canstat value ; to make sure same value. iorwf tempcancon ; copy icode bits to win bits. movff tempcancon, cancon ; copy the result to actual cancon ; access current buffer? ; user code ; restore cancon.win bits movf cancon, w ; preserve current non win bits andlw b?11110001? iorwf tempcancon ; restore original win bits ; do not need to restore canstat - it is read-only register. ; return from interrupt or check for another module interrupt source
pic18f2585/2680/4585/4680 ds39625b-page 280 preliminary ? 2004 microchip technology inc. register 23-3: ecancon: enhanced can control register r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 mdsel1 (1) mdsel0 (1) fifowm (2) ewin4 ewin3 ewin2 ewin1 ewin0 bit 7 bit 0 bit 7-6 mdsel1:mdsel0: mode select bits (1) 00 = legacy mode (mode 0, default) 01 = enhanced legacy mode (mode 1) 10 = enhanced fifo mode (mode 2) 11 = reserved bit 5 fifowm: fifo high water mark bit (2) 1 = will cause fifo interrupt when one receive buffer remains (3) 0 = will cause fifo interrupt when four receive buffers remain bit 4-0 ewin4:ewin0: enhanced window address bits these bits map the group of 16 banked can sfrs into access bank addresses 0f60-0f6dh. exact group of registers to map is determined by binary value of these bits. mode 0: unimplemented: read as ? 0 ? mode 1, 2: 00000 = acceptance filters 0, 1, 2 and brgcon2, 3 00001 = acceptance filters 3, 4, 5 and brgcon1, ciocon 00010 = acceptance filter masks, error and interrupt control 00011 = transmit buffer 0 00100 = transmit buffer 1 00101 = transmit buffer 2 00110 = acceptance filters 6, 7, 8 00111 = acceptance filters 9, 10, 11 01000 = acceptance filters 12, 13, 14 01001 = acceptance filters 15 01010 - 01110 = reserved 01111 = rxint0, rxint1 10000 = receive buffer 0 10001 = receive buffer 1 10010 = tx/rx buffer 0 10011 = tx/rx buffer 1 10100 = tx/rx buffer 2 10101 = tx/rx buffer 3 10110 = tx/rx buffer 4 10111 = tx/rx buffer 5 11000 - 11111 = reserved note 1: these bits can only be changed in configuration mode. see register 23-1 to change to configuration mode. 2: this bit is used in mode 2 only. 3: fifo length of 4 or less will cause this bit to be set. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 281 pic18f2585/2680/4585/4680 register 23-4: comstat: communication stat us register mode 0 r/c-0 r/c-0 r-0 r-0 r-0 r-0 r-0 r-0 rxb0ovfl rxb1ovfl txbo txbp rxbp txwarn rxwarn ewarn mode 1 r/c-0 r/c-0 r-0 r-0 r-0 r-0 r-0 r-0 ? rxbnovfl txb0 txbp rxbp txwarn rxwarn ewarn mode 2 r/c-0 r/c-0 r-0 r-0 r-0 r-0 r-0 r-0 fifoempty rxbnovfl txbo txbp rxbp txwarn rxwarn ewarn bit 7 bit 0 bit 7 mode 0: rxb0ovfl: receive buffer 0 overflow bit 1 = receive buffer 0 overflowed 0 = receive buffer 0 has not overflowed mode 1: unimplemented: read as ? 0 ? mode 2: fifoempty : fifo not empty bit 1 = receive fifo is not empty 0 = receive fifo is empty bit 6 mode 0: rxb1ovfl: receive buffer 1 overflow bit 1 = receive buffer 1 overflowed 0 = receive buffer 1 has not overflowed mode 1, 2: rxbnovfl: receive buffer n overflow bit 1 = receive buffer n has overflowed 0 = receive buffer n has not overflowed bit 5 txbo: transmitter bus-off bit 1 = transmit error counter > 255 0 = transmit error counter 255 bit 4 txbp: transmitter bus passive bit 1 = transmit error counter > 127 0 = transmit error counter 127 bit 3 rxbp: receiver bus passive bit 1 = receive error counter > 127 0 = receive error counter 127 bit 2 txwarn: transmitter warning bit 1 = transmit error counter > 95 0 = transmit error counter 95 bit 1 rxwarn: receiver warning bit 1 = 127 receive error counter > 95 0 = receive error counter 95 bit 0 ewarn: error warning bit this bit is a flag of the rxwarn and txwarn bits. 1 = the rxwarn or the txwarn bits are set 0 = neither the rxwarn or the txwarn bits are set legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 282 preliminary ? 2004 microchip technology inc. 23.2.2 dedicated can transmit buffer registers this section describes the dedicated can transmit buffer registers and their associated control registers. register 23-5: txbncon: transmit buffer n control registers [0 n 2] mode 0 r/c-0 r-0 r-0 r-0 r/w-0 u-0 r/w-0 r/w-0 txbif txabt (1) txlarb (1) txerr (1) txreq (2) ? txpri1 (3) txpri0 (3) mode 1, 2 r/c-0 r-0 r-0 r-0 r/w-0 u-0 r/w-0 r/w-0 txbif txabt (1) txlarb (1) txerr (1) txreq (2) ? txpri1 (3) txpri0 (3) bit 7 bit 0 bit 7 txbif: transmit buffer interrupt flag bit 1 = transmit buffer has completed transmission of message and may be reloaded 0 = transmit buffer has not completed transmission of a message bit 6 txabt: transmission aborted status bit (1) 1 = message was aborted 0 = message was not aborted bit 5 txlarb: transmission lost arbitration status bit (1) 1 = message lost arbitration while being sent 0 = message did not lose arbitration while being sent bit 4 txerr: transmission error detected status bit (1) 1 = a bus error occurred while the message was being sent 0 = a bus error did not occur while the message was being sent bit 3 txreq: transmit request status bit (2) 1 = requests sending a message. clears the txabt, txlarb and txerr bits. 0 = automatically cleared when the message is successfully sent bit 2 unimplemented: read as ? 0 ? bit 1-0 txpri1:txpri0: transmit priority bits (3) 11 = priority level 3 (highest priority) 10 = priority level 2 01 = priority level 1 00 = priority level 0 (lowest priority) note 1: this bit is automatically cleared when txreq is set. 2: while txreq is set, transmit buffer registers remain read-only. clearing this bit in software while the bit is set will request a message abort. 3: these bits define the order in which transmit buffers will be transferred. they do not alter the can message identifier. legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 283 pic18f2585/2680/4585/4680 register 23-6: txbnsidh: transmit buffer n standard identifier registers, high byte [0 n 2] register 23-7: txbnsidl: transmit buffer n standard identifier registers, low byte [0 n 2] register 23-8: txbneidh: transmit buffer n extended identifier registers, high byte [0 n 2] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier bits (if exide (txbnsidl<3>) = 0 ) extended identifier bits eid28:eid21 (if exide = 1 ). legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x u-0 r/w-x u-0 r/w-x r/w-x sid2 sid1 sid0 ? exide ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier bits (if exide (txbnsidl<3>) = 0 ) extended identifier bits eid20:eid18 (if exide = 1 ). bit 4 unimplemented: read as ? 0 ? bit 3 exide: extended identifier enable bit 1 = message will transmit extended id, sid10:sid0 become eid28:eid18 0 = message will transmit standard id, eid17:eid0 are ignored bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier bits (not used when transmitting standard identifier message) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 284 preliminary ? 2004 microchip technology inc. register 23-9: txbneidl: transmit buffe r n extended identifier registers, low byte [0 n 2] register 23-10: txbndm: transmit buffer n data field byte m registers [0 n 2, 0 m 7] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier bits (not used when transmitting standard identifier message) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x txbndm7 txbndm6 txbndm5 txbndm4 txbndm3 txbndm2 txbndm1 txbndm0 bit 7 bit 0 bit 7-0 txbndm7:txbndm0: transmit buffer n data field byte m bits (where 0 n < 3 and 0 m < 8) each transmit buffer has an array of registers. for example, transmit buffer 0 has 7 registers: txb0d0 to txb0d7. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 285 pic18f2585/2680/4585/4680 register 23-11: txbndlc: transmit buffer n data length code registers [0 n 2 ] register 23-12: txerrcnt: transmit error count register u-0 r/w-x u-0 u-0 r/w-x r/w-x r/w-x r/w-x ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 txrtr: transmit remote frame transmission request bit 1 = transmitted message will have txrtr bit set 0 = transmitted message will have txrtr bit cleared bit 5-4 unimplemented: read as ? 0 ? bit 3-0 dlc3:dlc0: data length code bits 1111 = reserved 1110 = reserved 1101 = reserved 1100 = reserved 1011 = reserved 1010 = reserved 1001 = reserved 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 bytes 0000 = data length = 0 bytes legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r-0 r-0 r-0 r-0 r-0 r-0 r-0 r-0 tec7 tec6 tec5 tec4 tec3 tec2 tec1 tec0 bit 7 bit 0 bit 7-0 tec7:tec0: transmit error counter bits this register contains a value which is derived from the rate at which errors occur. when the error count overflows, the bus-off state occurs. when the bus has 128 occurrences of 11 consecutive recessive bits, the counter value is cleared. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 286 preliminary ? 2004 microchip technology inc. example 23-3: transmitting a can message using banked method example 23-4: transmitting a can message using win bits ; need to transmit standard identifier message 123h using txb0 buffer. ; to successfully transmit, can module must be either in normal or loopback mode. ; txb0 buffer is not in access bank. and since we want banked method, we need to make sure ; that correct bank is selected. banksel txb0con ; one banksel in beginning will make sure that we are ; in correct bank for rest of the buffer access. ; now load transmit data into txb0 buffer. movlw my_data_byte1 ; load first data byte into buffer movwf txb0d0 ; compiler will automatically set ?banked? bit ; load rest of data bytes - up to 8 bytes into txb0 buffer. ... ; load message identifier movlw 60h ; load sid2:sid0, exide = 0 movwf txb0sidl movlw 24h ; load sid10:sid3 movwf txb0sidh ; no need to load txb0eidl:txb0eidh, as we are transmitting standard identifier message only. ; now that all data bytes are loaded, mark it for transmission. movlw b?00001000? ; normal priority; request transmission movwf txb0con ; if required, wait for message to get transmitted btfsc txb0con, txreq ; is it transmitted? bra $-2 ; no. continue to wait... ; message is transmitted. ; need to transmit standard identifier message 123h using txb0 buffer. ; to successfully transmit, can module must be either in normal or loopback mode. ; txb0 buffer is not in access bank. use win bits to map it to rxb0 area. movf cancon, w ; win bits are in lower 4 bits only. read cancon ; register to preserve all other bits. if operation ; mode is already known, there is no need to preserve ; other bits. andlw b?11110000? ; clear win bits. iorlw b?00001000? ; select transmit buffer 0 movwf cancon ; apply the changes. ; now txb0 is mapped in place of rxb0. all future access to rxb0 registers will actually ; yield txb0 register values. ; load transmit data into txb0 buffer. movlw my_data_byte1 ; load first data byte into buffer movwf rxb0d0 ; access txb0d0 via rxb0d0 address. ; load rest of the data bytes - up to 8 bytes into ?txb0? buffer using rxb0 registers. ... ; load message identifier movlw 60h ; load sid2:sid0, exide = 0 movwf rxb0sidl movlw 24h ; load sid10:sid3 movwf rxb0sidh ; no need to load rxb0eidl:rxb0eidh, as we are transmitting standard identifier message only. ; now that all data bytes are loaded, mark it for transmission. movlw b?00001000? ; normal priority; request transmission movwf rxb0con ; if required, wait for message to get transmitted btfsc rxb0con, txreq ; is it transmitted? bra $-2 ; no. continue to wait... ; message is transmitted. ; if required, reset the win bits to default state.
? 2004 microchip technology inc. preliminary ds39625b-page 287 pic18f2585/2680/4585/4680 23.2.3 dedicated can receive buffer registers this section shows the dedicated can receive buffer registers with their associated control registers. register 23-13: rxb0con: receive buffer 0 control register mode 0 r/c-0 r/w-0 r/w-0 u-0 r-0 r/w-0 r-0 r-0 rxful (1) rxm1 rxm0 ? rxrtrro rxb0dben jtoff (2) filhit0 mode 1, 2 r/c-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 rxful (1) rxm1 rtrro filhit4 filhit3 filhit2 filhit1 filhit0 bit 7 bit 0 bit 7 rxful: receive full status bit (1) 1 = receive buffer contains a received message 0 = receive buffer is open to receive a new message bit 6 mode 0: rxm1: receive buffer mode bit 1 combines with rxm0 to form rxm<1:0> bits (see bit 5). 11 = receive all messages (including those with errors); filter criteria is ignored 10 = receive only valid messages with extended identifier; exiden in rxfnsidl must be ? 1 ? 01 = receive only valid messages with standard identifier; exiden in rxfnsidl must be ? 0 ? 00 = receive all valid messages as per exiden bit in rxfnsidl register mode 1, 2: rxm1 : receive buffer mode bit 1 1 = receive all messages (including those with errors); acceptance filters are ignored 0 = receive all valid messages as per acceptance filters bit 5 mode 0: rxm0: receive buffer mode bit 0 combines with rxm1 to form rxm<1:0> bits (see bit 6). mode 1, 2: rtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received bit 4 mode 0: unimplemented: read as ? 0 ? mode 1, 2: filhit4: filter hit bit 4 this bit combines with other bits to form filter acceptance bits <4:0>. bit 3 mode 0: rxrtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received mode 1, 2: filhit3: filter hit bit 3 this bit combines with other bits to form filter acceptance bits <4:0>.
pic18f2585/2680/4585/4680 ds39625b-page 288 preliminary ? 2004 microchip technology inc. register 23-13: rxb0con: receive buffer 0 control register (continued) bit 2 mode 0: rxb0dben: receive buffer 0 double-buffer enable bit 1 = receive buffer 0 overflow will write to receive buffer 1 0 = no receive buffer 0 overflow to receive buffer 1 mode 1, 2: filhit2: filter hit bit 2 this bit combines with other bits to form filter acceptance bits <4:0>. bit 1 mode 0: jtoff: jump table offset bit (read-only copy of rxb0dben) (2) 1 = allows jump table offset between 6 and 7 0 = allows jump table offset between 1 and 0 mode 1, 2: filhit1: filter hit bit 1 this bit combines with other bits to form filter acceptance bits <4:0>. bit 0 mode 0: filhit0: filter hit bit 0 this bit indicates which acceptance filter enabled the message reception into receive buffer 0. 1 = acceptance filter 1 (rxf1) 0 = acceptance filter 0 (rxf0) mode 1, 2: filhit0: filter hit bit 0 this bit, in combination with filhit<4:1>, indicates which acceptance filter enabled the message reception into this receive buffer. 01111 = acceptance filter 15 (rxf15) 01110 = acceptance filter 14 (rxf14) ... 00000 = acceptance filter 0 (rxf0) note 1: this bit is set by the can module upon receiving a message and must be cleared by software after the buffer is read. as long as rxful is set, no new message will be loaded and buffer will be considered full. after clearing the rxful flag, the pir3 bit, rxb0if, can be cleared. if rxb0if is cleared, but rxful is not cleared, then rxb0if is set again. 2: this bit allows same filter jump table for both rxb0con and rxb1con. legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 289 pic18f2585/2680/4585/4680 register 23-14: rxb1con: receive buffer 1 control register mode 0 r/c-0 r/w-0 r/w-0 u-0 r-0 r/w-0 r-0 r-0 rxful (1) rxm1 rxm0 ? rxrtrro filhit2 filhit1 filhit0 mode 1, 2 r/c-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 rxful (1) rxm1 rtrro filhit4 filhit3 filhit2 filhit1 filhit0 bit 7 bit 0 bit 7 rxful: receive full status bit (1) 1 = receive buffer contains a received message 0 = receive buffer is open to receive a new message note 1: this bit is set by the can module upon receiving a message and must be cleared by software after the buffer is read. as long as rxful is set, no new message will be loaded and buffer will be considered full. bit 6 mode 0: rxm1: receive buffer mode bit 1 combines with rxm0 to form rxm<1:0> bits (see bit 5). 11 = receive all messages (including those with errors); filter criteria is ignored 10 = receive only valid messages with extended identifier; exiden in rxfnsidl must be ? 1 ? 01 = receive only valid messages with standard identifier, exiden in rxfnsidl must be ? 0 ? 00 = receive all valid messages as per exiden bit in rxfnsidl register mode 1, 2: rxm1: receive buffer mode bit 1 = receive all messages (including those with errors); acceptance filters are ignored 0 = receive all valid messages as per acceptance filters bit 5 mode 0: rxm0: receive buffer mode bit 0 combines with rxm1 to form rxm<1:0> bits (see bit 6). mode 1, 2: rtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received bit 4 mode 0: unimplemented: read as ? 0 ? mode 1, 2: filhit4: filter hit bit 4 this bit combines with other bits to form filter acceptance bits <4:0>. bit 3 mode 0: rxrtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received mode 1, 2: filhit3: filter hit bit 3 this bit combines with other bits to form filter acceptance bits <4:0>.
pic18f2585/2680/4585/4680 ds39625b-page 290 preliminary ? 2004 microchip technology inc. register 23-14: rxb1con: receive buffer 1 control register (continued) register 23-15: rxbnsidh: receive buffer n standard identifier registers, high byte [0 n 1] bit 2-0 mode 0: filhit2:filhit0: filter hit bits these bits indicate which acceptance filter enabled the last message reception into receive buffer 1. 111 = reserved 110 = reserved 101 = acceptance filter 5 (rxf5) 100 = acceptance filter 4 (rxf4) 011 = acceptance filter 3 (rxf3) 010 = acceptance filter 2 (rxf2) 001 = acceptance filter 1 (rxf1), only possible when rxb0dben bit is set 000 = acceptance filter 0 (rxf0), only possible when rxb0dben bit is set mode 1, 2: filhit2:filhit0 filter hit bits <2:0> these bits, in combination with filhit<4:3>, indicate which acceptance filter enabled the message reception into this receive buffer. 01111 = acceptance filter 15 (rxf15) 01110 = acceptance filter 14 (rxf14) ... 00000 = acceptance filter 0 (rxf0) legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r-x r-x r-x r-x r-x r-x r-x r-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier bits (if exid (rxbnsidl<3>) = 0 ) extended identifier bits eid28:eid21 (if exid = 1 ). legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 291 pic18f2585/2680/4585/4680 register 23-16: rxbnsidl: receive buffer n standard identifier registers, low byte [0 n 1] register 23-17: rxbneidh: receive buffer n extended identifier registers, high byte [0 n 1] register 23-18: rxbneidl: receive buffer n extended identifier registers, low byte [0 n 1] r-x r-x r-x r-x r-x u-0 r-x r-x sid2 sid1 sid0 srr exid ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier bits (if exid = 0 ) extended identifier bits eid20:eid18 (if exid = 1 ). bit 4 srr: substitute remote request bit this bit is always ? 0 ? when exid = 1 or equal to the value of rxrtrro (rbxncon<3>) when exid = 0 . bit 3 exid: extended identifier bit 1 = received message is an extended data frame, sid10:sid0 are eid28:eid18 0 = received message is a standard data frame bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r-x r-x r-x r-x r-x r-x r-x r-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r-x r-x r-x r-x r-x r-x r-x r-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 292 preliminary ? 2004 microchip technology inc. register 23-19: rxbndlc: receive buffer n data length code registers [0 n 1 ] register 23-20: rxbndm: receive buffer n data field byte m registers [0 n 1, 0 m 7] u-0 r-x r-x r-x r-x r-x r-x r-x ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 rxrtr: receiver remote transmission request bit 1 = remote transfer request 0 = no remote transfer request bit 5 rb1: reserved bit 1 reserved by can spec and read as ? 0 ?. bit 4 rb0: reserved bit 0 reserved by can spec and read as ? 0 ?. bit 3-0 dlc3:dlc0: data length code bits 1111 = invalid 1110 = invalid 1101 = invalid 1100 = invalid 1011 = invalid 1010 = invalid 1001 = invalid 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 bytes 0000 = data length = 0 bytes legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r-x r-x r-x r-x r-x r-x r-x r-x rxbndm7 rxbndm6 rxbndm5 rxbndm4 r xbndm3 rxbndm2 rxbndm1 rxbndm0 bit 7 bit 0 bit 7-0 rxbndm7:rxbndm0: receive buffer n data field byte m bits (where 0 n < 1 and 0 < m < 7) each receive buffer has an array of registers. for example, receive buffer 0 has 8 registers: rxb0d0 to rxb0d7. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 293 pic18f2585/2680/4585/4680 register 23-21: rxerrcnt: receive error count register example 23-5: reading a can message r-0 r-0 r-0 r-0 r-0 r-0 r-0 r-0 rec7 rec6 rec5 rec4 rec3 rec2 rec1 rec0 bit 7 bit 0 bit 7-0 rec7:rec0: receive error counter bits this register contains the receive error value as defined by the can specifications. when rxerrcnt > 127, the module will go into an error-passive state. rxerrcnt does not have the ability to put the module in ?bus-off? state. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown ; need to read a pending message from rxb0 buffer. ; to receive any message, filter, mask and rxm1:rxm0 bits in rxb0con registers must be ; programmed correctly. ; ; make sure that there is a message pending in rxb0. btfss rxb0con, rxful ; does rxb0 contain a message? bra nomessage ; no. handle this situation... ; we have verified that a message is pending in rxb0 buffer. ; if this buffer can receive both standard or extended identifier messages, ; identify type of message received. btfss rxb0sidl, exid ; is this extended identifier? bra standardmessage ; no. this is standard identifier message. ; yes. this is extended identifier message. ; read all 29-bits of extended identifier message. ... ; now read all data bytes movff rxb0do, my_data_byte1 ... ; once entire message is read, mark the rxb0 that it is read and no longer full. bcf rxb0con, rxful ; this will allow can module to load new messages ; into this buffer. ...
pic18f2585/2680/4585/4680 ds39625b-page 294 preliminary ? 2004 microchip technology inc. 23.2.3.1 programmable tx/rx and auto-rtr buffers the ecan module contains 6 message buffers that can be programmed as transmit or receive buffers. any of these buffers can also be programmed to automatically handle rtr messages. register 23-22: bncon: tx/rx buffer n control registers in receive mode [0 n 5, txnen (bsel0) = 0 ] (1) note: these registers are not used in mode 0. r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 rxful (2) rxm1 rxrtrro filhit4 filhit3 filhit2 filhit1 filhit0 bit 7 bit 0 bit 7 rxful: receive full status bit (2) 1 = receive buffer contains a received message 0 = receive buffer is open to receive a new message bit 6 rxm1: receive buffer mode bit 1 = receive all messages including partial and invalid (acceptance filters are ignored) 0 = receive all valid messages as per acceptance filters bit 5 rxrtrro: read-only remote transmission request for received message bit 1 = received message is a remote transmission request 0 = received message is not a remote transmission request bit 4-0 filhit4:filhit0: filter hit bits these bits indicate which acceptance filter enabled the last message reception into this buffer. 01111 = acceptance filter 15 (rxf15) 01110 = acceptance filter 14 (rxf14) ... 00001 = acceptance filter 1 (rxf1) 00000 = acceptance filter 0 (rxf0) note 1: these registers are available in mode 1 and 2 only. 2: this bit is set by the can module upon receiving a message and must be cleared by software after the buffer is read. as long as rxful is set, no new message will be loaded and the buffer will be considered full. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 295 pic18f2585/2680/4585/4680 register 23-23: bncon: tx/rx buffer n control registers in transmit mode [0 n 5, txnen (bsel0) = 1 ] (1) r/w-0 r-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 txbif txabt txlarb txerr txreq rtren txpri1 txpri0 bit 7 bit 0 bit 7 txbif: transmit buffer interrupt flag bit (3) 1 = a message is successfully transmitted 0 = no message was transmitted bit 6 txabt: transmission aborted status bit (3) 1 = message was aborted 0 = message was not aborted bit 5 txlarb: transmission lost arbitration status bit (3) 1 = message lost arbitration while being sent 0 = message did not lose arbitration while being sent bit 4 txerr: transmission error detected status bit (3) 1 = a bus error occurred while the message was being sent 0 = a bus error did not occur while the message was being sent bit 3 txreq: transmit request status bit (2,4) 1 = requests sending a message; clears the txabt, txlarb and txerr bits 0 = automatically cleared when the message is successfully sent bit 2 rtren: automatic remote transmission request enable bit 1 = when a remote transmission request is received, txreq will be automatically set 0 = when a remote transmission request is received, txreq will be unaffected bit 1-0 txpri1:txpri0: transmit priority bits (5) 11 = priority level 3 (highest priority) 10 = priority level 2 01 = priority level 1 00 = priority level 0 (lowest priority) note 1: these registers are available in mode 1 and 2 only. 2: clearing this bit in software while the bit is set will request a message abort. 3: this bit is automatically cleared when txreq is set. 4: while txreq is set or transmission is in progress, transmit buffer registers remain read-only. 5: these bits set the order in which the transmit buffer will be transferred. they do not alter the can message identifier. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 296 preliminary ? 2004 microchip technology inc. register 23-24: bnsidh: tx/rx buffer n standard identifier registers, high byte in receive mode [0 n 5, txnen (bsel0) = 0 ] (1) register 23-25: bnsidh: tx/rx buffer n standard identifier registers, high byte in transmit mode [0 n 5, txnen (bsel0) = 1 ] (1) r-x r-x r-x r-x r-x r-x r-x r-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier bits (if exide (bnsidl<3>) = 0 ) extended identifier bits eid28:eid21 (if exide = 1 ). note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier bits (if exide (bnsidl<3>) = 0 ) extended identifier bits eid28:eid21 (if exide = 1 ). note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 297 pic18f2585/2680/4585/4680 register 23-26: bnsidl: tx/rx buffer n standard identifier registers, low byte in receive mode [0 n 5, txnen (bsel0) = 0 ] (1) register 23-27: bnsidl: tx/rx buffer n standard identifier registers, low byte in transmit mode [0 n 5, txnen (bsel0) = 1 ] (1) r-x r-x r-x r-x r-x u-0 r-x r-x sid2 sid1 sid0 srr exid ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier bits (if exid = 0 ) extended identifier bits eid20:eid18 (if exid = 1 ). bit 4 srr: substitute remote transmission request bit (only when exid = 1 ) 1 = remote transmission request occurred 0 = no remote transmission request occurred bit 3 exid: extended identifier enable bit 1 = received message is an extended identifier frame (sid10:sid0 are eid28:eid18) 0 = received message is a standard identifier frame bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x u-0 r/w-x u-0 r/w-x r/w-x sid2 sid1 sid0 ? exide ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier bits (if exide = 0 ) extended identifier bits eid20:eid18 (if exide = 1 ). bit 4 unimplemented: read as ? 0 ? bit 3 exide: extended identifier enable bit 1 = received message is an extended identifier frame (sid10:sid0 are eid28:eid18) 0 = received message is a standard identifier frame bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 298 preliminary ? 2004 microchip technology inc. register 23-28: bneidh: tx/rx buffer n extended identifier registers, high byte in receive mode [0 n 5, txnen (bsel0) = 0 ] (1) register 23-29: bneidh: tx/rx buffer n extended identifier registers, high byte in transmit mode [0 n 5, txnen (bsel0) = 1] (1) register 23-30: bneidl: tx/rx buffer n extended identifier registers, low byte in receive mode [0 n 5, txnen (bsel) = 0 ] (1) r-x r-x r-x r-x r-x r-x r-x r-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r-x r-x r-x r-x r-x r-x r-x r-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 299 pic18f2585/2680/4585/4680 register 23-31: bneidl: tx/rx buffer n extended identifier registers, low byte in transmit mode [0 n 5, txnen (bsel) = 1 ] (1) register 23-32: bndm: tx/rx buffer n data field byte m registers in receive mode [0 n 5, 0 m 7, txnen (bsel) = 0 ] (1) register 23-33: bndm: tx/rx buffer n data field byte m registers in transmit mode [0 n 5, 0 m 7, txnen (bsel) = 1 ] (1) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier bits note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r-xr-xr-xr-xr-xr-xr-xr-x bndm7 bndm6 bndm5 bndm4 bndm3 bndm2 bndm1 bndm0 bit 7 bit 0 bit 7-0 bndm7:bndm0: receive buffer n data field byte m bits (where 0 n < 3 and 0 < m < 8) each receive buffer has an array of registers. for example, receive buffer 0 has 7 registers: b0d0 to b0d7. note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x bndm7 bndm6 bndm5 bndm4 bndm3 bndm2 bndm1 bndm0 bit 7 bit 0 bit 7-0 bndm7:bndm0: transmit buffer n data field byte m bits (where 0 n < 3 and 0 < m < 8) each transmit buffer has an array of registers. for example, transmit buffer 0 has 7 registers: txb0d0 to txb0d7. note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 300 preliminary ? 2004 microchip technology inc. register 23-34: bndlc: tx/rx buffer n data length code registers in receive mode [0 n 5, txnen (bsel) = 0 ] (1) u-0 r-x r-x r-x r-x r-x r-x r-x ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 rxrtr: receiver remote transmission request bit 1 = this is a remote transmission request 0 = this is not a remote transmission request bit 5 rb1: reserved bit 1 reserved by can spec and read as ? 0 ?. bit 4 rb0: reserved bit 0 reserved by can spec and read as ? 0 ?. bit 3-0 dlc3:dlc0: data length code bits 1111 = reserved 1110 = reserved 1101 = reserved 1100 = reserved 1011 = reserved 1010 = reserved 1001 = reserved 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 bytes 0000 = data length = 0 bytes note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 301 pic18f2585/2680/4585/4680 register 23-35: bndlc: tx/rx buffer n data length code registers in transmit mode [0 n 5, txnen (bsel) = 1 ] (1) register 23-36: bsel0: buffer select register 0 (1) u-0 r/w-x u-0 u-0 r/w-x r/w-x r/w-x r/w-x ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 txrtr: transmitter remote transmission request bit 1 = transmitted message will have rtr bit set 0 = transmitted message will have rtr bit cleared bit 5-4 unimplemented: read as ? 0 ? bit 3-0 dlc3:dlc0: data length code bits 1111 - 1001 = reserved 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 bytes 0000 = data length = 0 bytes note 1: these registers are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 b5txen b4txen b3txen b2txen b1txen b0txen ? ? bit 7 bit 0 bit 7-2 b5txen:b0txen: buffer 5 to buffer 0 transmit enable bit 1 = buffer is configured in transmit mode 0 = buffer is configured in receive mode bit 1-0 unimplemented: read as ? 0 ? note 1: this register is available in mode 1 and 2 only. . legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 302 preliminary ? 2004 microchip technology inc. 23.2.3.2 message acceptance filters and masks this section describes the message acceptance filters and masks for the can receive buffers. register 23-37: rxfnsidh: receive acceptance filter n standard identifier filter registers, high byte [0 n 15] (1) register 23-38: rxfnsidl: receive acceptance filter n standard identifier filter registers, low byte [0 n 15] (1) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier filter bits (if exiden = 0 ) extended identifier filter bits eid28:eid21 (if exiden = 1 ). note 1: registers rxf6sidh:rxf15sidh are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x u-0 r/w-x u-0 r/w-x r/w-x sid2 sid1 sid0 ? exiden (2) ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier filter bits (if exiden = 0 ) extended identifier filter bits eid20:eid18 (if exiden = 1 ). bit 4 unimplemented: read as ? 0 ? bit 3 exiden: extended identifier filter enable bit (2) 1 = filter will only accept extended id messages 0 = filter will only accept standard id messages bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier filter bits note 1: registers rxf6sidl:rxf15sidl are available in mode 1 and 2 only. 2: in mode 0, this bit must be set/cleared as required, irrespective of corresponding mask register value. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 303 pic18f2585/2680/4585/4680 register 23-39: rxfneidh: receive acceptance filter n extended identifier registers, high byte [0 n 15] (1) register 23-40: rxfneidl: receive acceptance filter n extended identifier registers, low byte [0 n 15] (1) register 23-41: rxmnsidh: receive acceptance mask n standard identifier mask registers, high byte [0 n 1] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier filter bits note 1: registers rxf6eidh:rxf15eidh are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier filter bits note 1: registers rxf6eidl:rxf15eidl are available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 bit 7-0 sid10:sid3: standard identifier mask bits or extended identifier mask bits eid28:eid21 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 304 preliminary ? 2004 microchip technology inc. register 23-42: rxmnsidl: receive acceptance mask n standard identifier mask registers, low byte [0 n 1] register 23-43: rxmneidh: receive acceptance mask n extended identifier mask registers, high byte [0 n 1] register 23-44: rxmneidl: receive acceptance mask n extended identifier mask registers, low byte [0 n 1] r/w-x r/w-x r/w-x u-0 r/w-0 u-0 r/w-x r/w-x sid2 sid1 sid0 ? exiden (1) ?eid17eid16 bit 7 bit 0 bit 7-5 sid2:sid0: standard identifier mask bits or extended identifier mask bits eid20:eid18 bit 4 unimplemented: read as ? 0 ? bit 3 mode 0: unimplemented: read as ? 0 ? mode 1, 2 : exiden: extended identifier filter enable mask bit (1) 1 = messages selected by the exiden bit in rxfnsidl will be accepted 0 = both standard and extended identifier messages will be accepted note 1: this bit is available in mode 1 and 2 only. bit 2 unimplemented: read as ? 0 ? bit 1-0 eid17:eid16: extended identifier mask bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 bit 7-0 eid15:eid8: extended identifier mask bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 bit 7-0 eid7:eid0: extended identifier mask bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 305 pic18f2585/2680/4585/4680 register 23-45: rxfconn: receive filter control register n [0 n 1] (1) register 23-46: sdflc: standard data bytes filter length count register (1) rxfcon0 r/w-0 r/w-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rxf7en rxf6en rxf5en rxf4en rxf3en rxf2en rxf1en rxf0en rxfcon1 r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 rxf15en rxf14en rxf13en rxf12en rxf11en rxf10en rxf9en rxf8en bit 7 bit 0 bit 7-0 rxfnen: receive filter n enable bits 0 = filter is disabled 1 = filter is enabled note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: registers 23-46 through 23-51are writable in configuration mode only. u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? flc4flc3flc2flc1flc0 bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4-0 flc4:flc0: filter length count bits mode 0: not used; forced to ? 00000 ?. 00000 - 10010 = 0 18 bits are available for standard data byte filter. actual number of bits used depends on dlc3:dlc0 bits (rxbndlc<3:0> or bndlc<3:0> if configured as rx buffer) of message being received. if dlc3:dlc0 = 0000 no bits will be compared with incoming data bits if dlc3:dlc0 = 0001 up to 8 data bits of rxfneid<7:0>, as determined by flc2:flc0, will be compared with the corresponding number of data bits of the incoming message if dlc3:dlc0 = 0010 up to 16 data bits of rxfneid<15:0>, as determined by flc3:flc0, will be compared with the corresponding number of data bits of the incoming message if dlc3:dlc0 = 0011 up to 18 data bits of rxfneid<17:0>, as determined by flc4:flc0, will be compared with the corresponding number of data bits of the incoming message note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 306 preliminary ? 2004 microchip technology inc. register 23-47: rxfbconn: receive filter buffer control register n (1) rxfbcon0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f1bp_3 f1bp_2 f1bp_1 f1bp_0 f 0bp_3 f0bp_2 f0bp_1 f0bp_0 rxfbcon1 r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-1 f3bp_3 f3bp_2 f3bp_1 f3bp_0 f 2bp_3 f2bp_2 f2bp_1 f2bp_0 rxfbcon2 r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-1 f5bp_3 f5bp_2 f5bp_1 f5bp_0 f 4bp_3 f4bp_2 f4bp_1 f4bp_0 rxfbcon3 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f7bp_3 f7bp_2 f7bp_1 f7bp_0 f 6bp_3 f6bp_2 f6bp_1 f6bp_0 rxfbcon4 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f9bp_3 f9bp_2 f9bp_1 f9bp_0 f 8bp_3 f8bp_2 f8bp_1 f8bp_0 rxfbcon5 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f11bp_3 f11bp_2 f11bp_1 f11bp_0 f10bp_3 f10bp_2 f10bp_1 f10bp_0 rxfbcon6 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f13bp_3 f13bp_2 f13bp_1 f13bp_0 f12bp_3 f12bp_2 f12bp_1 f12bp_0 rxfbcon7 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f15bp_3 f15bp_2 f15bp_1 f15bp_0 f14bp_3 f14bp_2 f14bp_1 f14bp_0 bit 7 bit 0 bit 7-0 fnbp_3:fnbp_0: filter n buffer pointer nibble bits 0000 = filter n is associated with rxb0 0001 = filter n is associated with rxb1 0010 = filter n is associated with b0 0011 = filter n is associated with b1 ... 0111 = filter n is associated with b5 1111-1000 = reserved note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 307 pic18f2585/2680/4585/4680 register 23-48: msel0: mask select register 0 (1) r/w-0 r/w-1 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 fil3_1 fil3_0 fil2_1 fil2_0 fil1_1 fil1_0 fil0_1 fil0_0 bit 7 bit 0 bit 7-6 fil3_1:fil3_0: filter 3 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil2_1:fil2_0: filter 2 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil1_1:fil1_0: filter 1 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil0_1:fil0_0: filter 0 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 308 preliminary ? 2004 microchip technology inc. register 23-49: msel1: mask select register 1 (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-1 fil7_1 fil7_0 fil6_1 fil6_0 fil5_1 fil5_0 fil4_1 fil4_0 bit 7 bit 0 bit 7-6 fil7_1:fil7_0: filter 7 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil6_1:fil6_0: filter 6 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil5_1:fil5_0: filter 5 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil4_1:fil4_0: filter 4 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 309 pic18f2585/2680/4585/4680 register 23-50: msel2: mask select register 2 (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 fil11_1 fil11_0 fil10_1 fil10_0 fil9_1 fil9_0 fil8_1 fil8_0 bit 7 bit 0 bit 7-6 fil11_1:fil11_0: filter 11 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil10_1:fil10_0: filter 10 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil9_1:fil9_0: filter 9 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil8_1:fil8_0: filter 8 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 310 preliminary ? 2004 microchip technology inc. register 23-51: msel3: mask select register 3 (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 fil15_1 fil15_0 fil14_1 fil14_0 fil13_1 fil13_0 fil12_1 fil12_0 bit 7 bit 0 bit 7-6 fil15_1:fil15_0: filter 15 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil14_1:fil14_0: filter 14 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil13_1:fil13_0: filter 13 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil12_1:fil12_0: filter 12 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 311 pic18f2585/2680/4585/4680 23.2.4 can baud rate registers this section describes the can baud rate registers. register 23-52: brgcon1: baud rate contro l register 1 note: these registers are writable in configuration mode only. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 sjw1 sjw0 brp5 brp4 brp3 brp2 brp1 brp0 bit 7 bit 0 bit 7-6 sjw1:sjw0: synchronized jump width bits 11 = synchronization jump width time = 4 x t q 10 = synchronization jump width time = 3 x t q 01 = synchronization jump width time = 2 x t q 00 = synchronization jump width time = 1 x t q bit 5-0 brp5:brp0: baud rate prescaler bits 111111 = t q = (2 x 64)/f osc 111110 = t q = (2 x 63)/f osc : : 000001 = t q = (2 x 2)/f osc 000000 = t q = (2 x 1)/f osc legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 312 preliminary ? 2004 microchip technology inc. register 23-53: brgcon2: baud rate contro l register 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 seg2phts sam seg1ph2 seg1ph1 seg1ph0 prseg2 prseg1 prseg0 bit 7 bit 0 bit 7 seg2phts: phase segment 2 time select bit 1 = freely programmable 0 = maximum of pheg1 or information processing time (ipt), whichever is greater bit 6 sam: sample of the can bus line bit 1 = bus line is sampled three times prior to the sample point 0 = bus line is sampled once at the sample point bit 5-3 seg1ph2:seg1ph0: phase segment 1 bits 111 = phase segment 1 time = 8 x t q 110 = phase segment 1 time = 7 x t q 101 = phase segment 1 time = 6 x t q 100 = phase segment 1 time = 5 x t q 011 = phase segment 1 time = 4 x t q 010 = phase segment 1 time = 3 x t q 001 = phase segment 1 time = 2 x t q 000 = phase segment 1 time = 1 x t q bit 2-0 prseg2:prseg0: propagation time select bits 111 = propagation time = 8 x t q 110 = propagation time = 7 x t q 101 = propagation time = 6 x t q 100 = propagation time = 5 x t q 011 = propagation time = 4 x t q 010 = propagation time = 3 x t q 001 = propagation time = 2 x t q 000 = propagation time = 1 x t q legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 313 pic18f2585/2680/4585/4680 register 23-54: brgcon3: baud rate contro l register 3 r/w-0 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 wakdis wakfil ? ? ? seg2ph2 (1) seg2ph1 (1) seg2ph0 (1) bit 7 bit 0 bit 7 wakdis: wake-up disable bit 1 = disable can bus activity wake-up feature 0 = enable can bus activity wake-up feature bit 6 wakfil: selects can bus line filter for wake-up bit 1 = use can bus line filter for wake-up 0 = can bus line filter is not used for wake-up bit 5-3 unimplemented: read as ? 0 ? bit 2-0 seg2ph2:seg2ph0: phase segment 2 time select bits (1) 111 = phase segment 2 time = 8 x t q 110 = phase segment 2 time = 7 x t q 101 = phase segment 2 time = 6 x t q 100 = phase segment 2 time = 5 x t q 011 = phase segment 2 time = 4 x t q 010 = phase segment 2 time = 3 x t q 001 = phase segment 2 time = 2 x t q 000 = phase segment 2 time = 1 x t q note 1: ignored if seg2phts bit (brgcon2<7>) is ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 314 preliminary ? 2004 microchip technology inc. 23.2.5 can module i/o control register this register controls the operation of the can module?s i/o pins in relation to the rest of the microcontroller. register 23-55: ciocon: can i/o control register u-0 u-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? ? endrhi (1) cancap ? ? ? ? bit 7 bit 0 bit 7-6 unimplemented: read as ? 0 ? bit 5 endrhi: enable drive high bit (1) 1 = cantx pin will drive v dd when recessive 0 = cantx pin will be tri-state when recessive note 1: always set this bit when using differential bus to avoid signal crosstalk in cantx from other nearby pins. bit 4 cancap: can message receive capture enable bit 1 = enable can capture, can message receive signal replaces input on rc2/ccp1 0 = disable can capture, rc2/ccp1 input to ccp1 module bit 3-0 unimplemented: read as ? 0 ? legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 315 pic18f2585/2680/4585/4680 23.2.6 can interrupt registers the registers in this section are the same as described in section 9.0 ?interrupts? . they are duplicated here for convenience. register 23-56: pir3: peripheral interrupt request (flag) register 3 mode 0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxif wakif errif txb2if txb1if (1) txb0if (1) rxb1if rxb0if mode 1, 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxif wakif errif txbnif txb1if (1) txb0if (1) rxbnif fifowmif bit 7 bit 0 bit 7 irxif: can invalid received message interrupt flag bit 1 = an invalid message has occurred on the can bus 0 = no invalid message on can bus bit 6 wakif: can bus activity wake-up interrupt flag bit 1 = activity on can bus has occurred 0 = no activity on can bus bit 5 errif: can bus error interrupt flag bit 1 = an error has occurred in the can module (multiple sources) 0 = no can module errors bit 4 when can is in mode 0: txb2if: can transmit buffer 2 interrupt flag bit 1 = transmit buffer 2 has completed transmission of a message and may be reloaded 0 = transmit buffer 2 has not completed transmission of a message when can is in mode 1 or 2: txbnif: any transmit buffer interrupt flag bit 1 = one or more transmit buffers have completed transmission of a message and may be reloaded 0 = no transmit buffer is ready for reload bit 3 txb1if: can transmit buffer 1 interrupt flag bit (1) 1 = transmit buffer 1 has completed transmission of a message and may be reloaded 0 = transmit buffer 1 has not completed transmission of a message bit 2 txb0if: can transmit buffer 0 interrupt flag bit (1) 1 = transmit buffer 0 has completed transmission of a message and may be reloaded 0 = transmit buffer 0 has not completed transmission of a message bit 1 when can is in mode 0: rxb1if: can receive buffer 1 interrupt flag bit 1 = receive buffer 1 has received a new message 0 = receive buffer 1 has not received a new message when can is in mode 1 or 2: rxbnif: any receive buffer interrupt flag bit 1 = one or more receive buffers has received a new message 0 = no receive buffer has received a new message bit 0 when can is in mode 0: rxb0if: can receive buffer 0 interrupt flag bit 1 = receive buffer 0 has received a new message 0 = receive buffer 0 has not received a new message when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmif: fifo watermark interrupt flag bit 1 = fifo high watermark is reached 0 = fifo high watermark is not reached note 1: in can mode 1 and 2, this bit is forced to ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 316 preliminary ? 2004 microchip technology inc. register 23-57: pie3: peripheral interrupt enable register mode 0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxie wakie errie txb2ie txb1ie (1) txb0ie (1) rxb1ie rxb0ie mode 1, 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxie wakie errie txbnie txb1ie (1) txb0ie (1) rxbnie fifowmie bit 7 bit 0 bit 7 irxie: can invalid received message interrupt enable bit 1 = enable invalid message received interrupt 0 = disable invalid message received interrupt bit 6 wakie: can bus activity wake-up interrupt enable bit 1 = enable bus activity wake-up interrupt 0 = disable bus activity wake-up interrupt bit 5 errie: can bus error interrupt enable bit 1 = enable can bus error interrupt 0 = disable can bus error interrupt bit 4 when can is in mode 0: txb2ie: can transmit buffer 2 interrupt enable bit 1 = enable transmit buffer 2 interrupt 0 = disable transmit buffer 2 interrupt when can is in mode 1 or 2: txbnie: can transmit buffer interrupts enable bit 1 = enable transmit buffer interrupt; individual interrupt is enabled by txbie and bie0 0 = disable all transmit buffer interrupts bit 3 txb1ie: can transmit buffer 1 interrupt enable bit (1) 1 = enable transmit buffer 1 interrupt 0 = disable transmit buffer 1 interrupt bit 2 txb0ie: can transmit buffer 0 interrupt enable bit (1) 1 = enable transmit buffer 0 interrupt 0 = disable transmit buffer 0 interrupt bit 1 when can is in mode 0: rxb1ie: can receive buffer 1 interrupt enable bit 1 = enable receive buffer 1 interrupt 0 = disable receive buffer 1 interrupt when can is in mode 1 or 2: rxbnie: can receive buffer interrupts enable bit 1 = enable receive buffer interrupt; individual interrupt is enabled by bie0 0 = disable all receive buffer interrupts bit 0 when can is in mode 0: rxb0ie: can receive buffer 0 interrupt enable bit 1 = enable receive buffer 0 interrupt 0 = disable receive buffer 0 interrupt when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmie: fifo watermark interrupt enable bit 1 = enable fifo watermark interrupt 0 = disable fifo watermark interrupt note 1: in can mode 1 and 2, this bit is forced to ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 317 pic18f2585/2680/4585/4680 register 23-58: ipr3: peripheral interrupt priority register 5 mode 0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 irxip wakip errip txb2ip txb1ip (1) txb0ip (1) rxb1ip rxb0ip mode 1, 2 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 irxip wakip errip txbnip txb1ip (1) txb0ip (1) rxbnip fifowmip bit 7 bit 0 bit 7 irxip: can invalid received message interrupt priority bit 1 = high priority 0 = low priority bit 6 wakip: can bus activity wake-up interrupt priority bit 1 = high priority 0 = low priority bit 5 errip: can bus error interrupt priority bit 1 = high priority 0 = low priority bit 4 when can is in mode 0: txb2ip: can transmit buffer 2 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1 or 2: txbnip: can transmit buffer interrupt priority bit 1 = high priority 0 = low priority bit 3 txb1ip: can transmit buffer 1 interrupt priority bit (1) 1 = high priority 0 = low priority bit 2 txb0ip: can transmit buffer 0 interrupt priority bit (1) 1 = high priority 0 = low priority bit 1 when can is in mode 0: rxb1ip: can receive buffer 1 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1 or 2: rxbnip: can receive buffer interrupts priority bit 1 = high priority 0 = low priority bit 0 when can is in mode 0: rxb0ip: can receive buffer 0 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmip: fifo watermark interrupt priority bit 1 = high priority 0 = low priority note 1: in can mode 1 and 2, this bit is forced to ? 0 ?. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic18f2585/2680/4585/4680 ds39625b-page 318 preliminary ? 2004 microchip technology inc. register 23-59: txbie: transmit buffers interrupt enable register (1) register 23-60: bie0: buffer interrupt enable register 0 (1) u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 ? ? ? txb2ie (2) txb1ie (2) txb0ie (2) ? ? bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4-2 txb2ie:txb0ie: transmit buffer 2-0 interrupt enable bit (2) 1 = transmit buffer interrupt is enabled 0 = transmit buffer interrupt is disabled bit 1-0 unimplemented: read as ? 0 ? note 1: this register is available in mode 1 and 2 only. 2: txbnie in pie3 register must be set to get an interrupt. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 b5ie (2) b4ie (2) b3ie (2) b2ie (2) b1ie (2) b0ie (2) rxb1ie (2) rxb0ie (2) bit 7 bit 0 bit 7-2 b5ie:b0ie: programmable transmit/receive buffer 5-0 interrupt enable bit (2) 1 = interrupt is enabled 0 = interrupt is disabled bit 1-0 rxb1ie:rxb0ie: dedicated receive buffer 1-0 interrupt enable bit (2) 1 = interrupt is enabled 0 = interrupt is disabled note 1: this register is available in mode 1 and 2 only. 2: either txbnie or rxbnie in pie3 register must be set to get an interrupt. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2004 microchip technology inc. preliminary ds39625b-page 319 pic18f2585/2680/4585/4680 table 23-1: can controller register map address (1) name address name address name address name f7fh spbrgh (3) f5fh cancon_ro0 f3fh cancon_ro2 f1fh rxm1eidl f7eh baudcon (3) f5eh canstat_ro0 f3eh canstat_ro2 f1eh rxm1eidh f7dh ? (4) f5dh rxb1d7 f3dh txb1d7 f1dh rxm1sidl f7ch ? (4) f5ch rxb1d6 f3ch txb1d6 f1ch rxm1sidh f7bh ? (4) f5bh rxb1d5 f3bh txb1d5 f1bh rxm0eidl f7ah ? (4) f5ah rxb1d4 f3ah txb1d4 f1ah rxm0eidh f79h eccp1del (3) f59h rxb1d3 f39h txb1d3 f19h rxm0sidl f78h ? (4) f58h rxb1d2 f38h txb1d2 f18h rxm0sidh f77h ecancon f57h rxb1d1 f37h txb1d1 f17h rxf5eidl f76h txerrcnt f56h rxb1d0 f36h txb1d0 f16h rxf5eidh f75h rxerrcnt f55h rxb1dlc f35h txb1dlc f15h rxf5sidl f74h comstat f54h rxb1eidl f34h txb1eidl f14h rxf5sidh f73h ciocon f53h rxb1eidh f33h txb1eidh f13h rxf4eidl f72h brgcon3 f52h rxb1sidl f32h txb1sidl f12h rxf4eidh f71h brgcon2 f51h rxb1sidh f31h txb1sidh f11h rxf4sidl f70h brgcon1 f50h rxb1con f30h txb1con f10h rxf4sidh f6fh cancon f4fh cancon_ro1 (2) f2fh cancon_ro3 (2) f0fh rxf3eidl f6eh canstat f4eh canstat_ro1 (2) f2eh canstat_ro3 (2) f0eh rxf3eidh f6dh rxb0d7 f4dh txb0d7 f2dh txb2d7 f0dh rxf3sidl f6ch rxb0d6 f4ch txb0d6 f2ch txb2d6 f0ch rxf3sidh f6bh rxb0d5 f4bh txb0d5 f2 bh txb2d5 f0bh rxf2eidl f6ah rxb0d4 f4ah txb0d4 f2ah txb2d4 f0ah rxf2eidh f69h rxb0d3 f49h txb0d3 f29h txb2d3 f09h rxf2sidl f68h rxb0d2 f48h txb0d2 f28h txb2d2 f08h rxf2sidh f67h rxb0d1 f47h txb0d1 f27h txb2d1 f07h rxf1eidl f66h rxb0d0 f46h txb0d0 f26h txb2d0 f06h rxf1eidh f65h rxb0dlc f45h txb0dlc f25h txb2dlc f05h rxf1sidl f64h rxb0eidl f44h txb0eidl f24h txb2eidl f04h rxf1sidh f63h rxb0eidh f43h txb0eidh f23h txb2eidh f03h rxf0eidl f62h rxb0sidl f42h txb0sidl f22h txb2sidl f02h rxf0eidh f61h rxb0sidh f41h txb0sidh f21h txb2sidh f01h rxf0sidl f60h rxb0con f40h txb0con f20h txb2con f00h rxf0sidh note 1: shaded registers are available in access bank low area, while the rest are available in bank 15. 2: canstat register is repeated in these locations to simplify application firmware. unique names are given for each instance of the controller register due to the microchip header file requirement. 3: these registers are not can registers. 4: unimplemented registers are read as ? 0 ?.
pic18f2585/2680/4585/4680 ds39625b-page 320 preliminary ? 2004 microchip technology inc. effh ? (4) edfh ? (4) ebfh ? (4) e9fh ? (4) efeh ? (4) edeh ? (4) ebeh ? (4) e9eh ? (4) efdh ? (4) eddh ? (4) ebdh ? (4) e9dh ? (4) efch ? (4) edch ? (4) ebch ? (4) e9ch ? (4) efbh ? (4) edbh ? (4) ebbh ? (4) e9bh ? (4) efah ? (4) edah ? (4) ebah ? (4) e9ah ? (4) ef9h ? (4) ed9h ? (4) eb9h ? (4) e99h ? (4) ef8h ? (4) ed8h ? (4) eb8h ? (4) e98h ? (4) ef7h ? (4) ed7h ? (4) eb7h ? (4) e97h ? (4) ef6h ? (4) ed6h ? (4) eb6h ? (4) e96h ? (4) ef5h ? (4) ed5h ? (4) eb5h ? (4) e95h ? (4) ef4h ? (4) ed4h ? (4) eb4h ? (4) e94h ? (4) ef3h ? (4) ed3h ? (4) eb3h ? (4) e93h ? (4) ef2h ? (4) ed2h ? (4) eb2h ? (4) e92h ? (4) ef1h ? (4) ed1h ? (4) eb1h ? (4) e91h ? (4) ef0h ? (4) ed0h ? (4) eb0h ? (4) e90h ? (4) eefh ? (4) ecfh ? (4) eafh ? (4) e8fh ? (4) eeeh ? (4) eceh ? (4) eaeh ? (4) e8eh ? (4) eedh ? (4) ecdh ? (4) eadh ? (4) e8dh ? (4) eech ? (4) ecch ? (4) each ? (4) e8ch ? (4) eebh ? (4) ecbh ? (4) eabh ? (4) e8bh ? (4) eeah ? (4) ecah ? (4) eaah ? (4) e8ah ? (4) ee9h ? (4) ec9h ? (4) ea9h ? (4) e89h ? (4) ee8h ? (4) ec8h ? (4) ea8h ? (4) e88h ? (4) ee7h ? (4) ec7h ? (4) ea7h ? (4) e87h ? (4) ee6h ? (4) ec6h ? (4) ea6h ? (4) e86h ? (4) ee5h ? (4) ec5h ? (4) ea5h ? (4) e85h ? (4) ee4h ? (4) ec4h ? (4) ea4h ? (4) e84h ? (4) ee3h ? (4) ec3h ? (4) ea3h ? (4) e83h ? (4) ee2h ? (4) ec2h ? (4) ea2h ? (4) e82h ? (4) ee1h ? (4) ec1h ? (4) ea1h ? (4) e81h ? (4) ee0h ? (4) ec0h ? (4) ea0h ? (4) e80h ? (4) table 23-1: can controller register map (continued) address (1) name address name address name address name note 1: shaded registers are available in access bank low area, while the rest are available in bank 15. 2: canstat register is repeated in these locations to simplify application firmware. unique names are given for each instance of the controller register due to the microchip header file requirement. 3: these registers are not can registers. 4: unimplemented registers are read as ? 0 ?.
? 2004 microchip technology inc. preliminary ds39625b-page 321 pic18f2585/2680/4585/4680 e7fh cancon_ro4 (2) e5fh cancon_ro6 (2) e3fh cancon_ro8 (2) e1fh ? (4) e7eh canstat_ro4 (2) e5eh canstat_ro6 (2) e3eh canstat_ro8 (2) e1eh ? (4) e7dh b5d7 e5dh b3d7 e3dh b1d7 e1dh ? (4) e7ch b5d6 e5ch b3d6 e3ch b1d6 e1ch ? (4) e7bh b5d5 e5bh b3d5 e3bh b1d5 e1bh ? (4) e7ah b5d4 e5ah b3d4 e3ah b1d4 e1ah ? (4) e79h b5d3 e59h b3d3 e39h b1d3 e19h ? (4) e78h b5d2 e58h b3d2 e38h b1d2 e18h ? (4) e77h b5d1 e57h b3d1 e37h b1d1 e17h ? (4) e76h b5d0 e56h b3d0 e36h b1d0 e16h ? (4) e75h b5dlc e55h b3dlc e35h b1dlc e15h ? (4) e74h b5eidl e54h b3eidl e34h b1eidl e14h ? (4) e73h b5eidh e53h b3eidh e33h b1eidh e13h ? (4) e72h b5sidl e52h b3sidl e32h b1sidl e12h ? (4) e71h b5sidh e51h b3sidh e31h b1sidh e11h ? (4) e70h b5con e50h b3con e30h b1con e10h ? (4) e6fh cancon_ro5 e4fh cancon_ro7 e2fh cancon_ro9 e0fh ? (4) e6eh canstat_ro5 e4eh canstat_ro7 e2eh canstat_ro9 e0eh ? (4) e6dh b4d7 e4dh b2d7 e2dh b0d7 e0dh ? (4) e6ch b4d6 e4ch b2d6 e2ch b0d6 e0ch ? (4) e6bh b4d5 e4bh b2d5 e2bh b0d5 e0bh ? (4) e6ah b4d4 e4ah b2d4 e2ah b0d4 e0ah ? (4) e69h b4d3 e49h b2d3 e29h b0d3 e09h ? (4) e68h b4d2 e48h b2d2 e28h b0d2 e08h ? (4) e67h b4d1 e47h b2d1 e27h b0d1 e07h ? (4) e66h b4d0 e46h b2d0 e26h b0d0 e06h ? (4) e65h b4dlc e45h b2dlc e25h b0dlc e05h ? (4) e64h b4eidl e44h b2eidl e24h b0eidl e04h ? (4) e63h b4eidh e43h b2eidh e23h b0eidh e03h ? (4) e62h b4sidl e42h b2sidl e22h b0sidl e02h ? (4) e61h b4sidh e41h b2sidh e21h b0sidh e01h ? (4) e60h b4con e40h b2con e20h b0con e00h ? (4) table 23-1: can controller register map (continued) address (1) name address name address name address name note 1: shaded registers are available in access bank low area, while the rest are available in bank 15. 2: canstat register is repeated in these locations to simplify application firmware. unique names are given for each instance of the controller register due to the microchip header file requirement. 3: these registers are not can registers. 4: unimplemented registers are read as ? 0 ?.
pic18f2585/2680/4585/4680 ds39625b-page 322 preliminary ? 2004 microchip technology inc. dffh ? (4) ddfh ? (4) dbfh ? (4) d9fh ? (4) dfeh ? (4) ddeh ? (4) dbeh ? (4) d9eh ? (4) dfdh ? (4) dddh ? (4) dbdh ? (4) d9dh ? (4) dfch txbie ddch ? (4) dbch ? (4) d9ch ? (4) dfbh ? (4) ddbh ? (4) dbbh ? (4) d9bh ? (4) dfah bie0 ddah ? (4) dbah ? (4) d9ah ? (4) df9h ? (4) dd9h ? (4) db9h ? (4) d99h ? (4) df8h bsel0 dd8h sdflc db8h ? (4) d98h ? (4) df7h ? (4) dd7h ? (4) db7h ? (4) d97h ? (4) df6h ? (4) dd6h ? (4) db6h ? (4) d96h ? (4) df5h ? (4) dd5h rxfcon1 db5h ? (4) d95h ? (4) df4h ? (4) dd4h rxfcon0 db4h ? (4) d94h ? (4) df3h msel3 dd3h ? (4) db3h ? (4) d93h rxf15eidl df2h msel2 dd2h ? (4) db2h ? (4) d92h rxf15eidh df1h msel1 dd1h ? (4) db1h ? (4) d91h rxf15sidl df0h msel0 dd0h ? (4) db0h ? (4) d90h rxf15sidh defh ? (4) dcfh ? (4) dafh ? (4) d8fh ? (4) deeh ? (4) dceh ? (4) daeh ? (4) d8eh ? (4) dedh ? (4) dcdh ? (4) dadh ? (4) d8dh ? (4) dech ? (4) dcch ? (4) dach ? (4) d8ch ? (4) debh ? (4) dcbh ? (4) dabh ? (4) d8bh rxf14eidl deah ? (4) dcah ? (4) daah ? (4) d8ah rxf14eidh de9h ? (4) dc9h ? (4) da9h ? (4) d89h rxf14sidl de8h ? (4) dc8h ? (4) da8h ? (4) d88h rxf14sidh de7h rxfbcon7 dc7h ? (4) da7h ? (4) d87h rxf13eidl de6h rxfbcon6 dc6h ? (4) da6h ? (4) d86h rxf13eidh de5h rxfbcon5 dc5h ? (4) da5h ? (4) d85h rxf13sidl de4h rxfbcon4 dc4h ? (4) da4h ? (4) d84h rxf13sidh de3h rxfbcon3 dc3h ? (4) da3h ? (4) d83h rxf12eidl de2h rxfbcon2 dc2h ? (4) da2h ? (4) d82h rxf12eidh de1h rxfbcon1 dc1h ? (4) da1h ? (4) d81h rxf12sidl de0h rxfbcon0 dc0h ? (4) da0h ? (4) d80h rxf12sidh table 23-1: can controller register map (continued) address (1) name address name address name address name note 1: shaded registers are available in access bank low area, while the rest are available in bank 15. 2: canstat register is repeated in these locations to simplify application firmware. unique names are given for each instance of the controller register due to the microchip header file requirement. 3: these registers are not can registers. 4: unimplemented registers are read as ? 0 ?.
? 2004 microchip technology inc. preliminary ds39625b-page 323 pic18f2585/2680/4585/4680 table 23-1: can controller register map (continued) address (1) name d7fh ? (4) d7eh ? (4) d7dh ? (4) d7ch ? (4) d7bh rxf11eidl d7ah rxf11eidh d79h rxf11sidl d78h rxf11sidh d77h rxf10eidl d76h rxf10eidh d75h rxf10sidl d74h rxf10sidh d73h rxf9eidl d72h rxf9eidh d71h rxf9sidl d70h rxf9sidh d6fh ? (4) d6eh ? (4) d6dh ? (4) d6ch ? (4) d6bh rxf8eidl d6ah rxf8eidh d69h rxf8sidl d68h rxf8sidh d67h rxf7eidl d66h rxf7eidh d65h rxf7sidl d64h rxf7sidh d63h rxf6eidl d62h rxf6eidh d61h rxf6sidl d60h rxf6sidh note 1: shaded registers are available in access bank low area while the rest are available in bank 15. 2: canstat register is repeated in these locations to simplify application firmware. unique names are given for each instance of the controller register due to the microchip header file requirement. 3: these registers are not can registers. 4: unimplemented registers are read as ? 0 ?.
pic18f2585/2680/4585/4680 ds39625b-page 324 preliminary ? 2004 microchip technology inc. 23.3 can modes of operation the pic18f2585/2680/4585/4680 has six main modes of operation:  configuration mode  disable mode  normal operation mode  listen only mode  loopback mode  error recognition mode all modes, except error recognition, are requested by setting the reqop bits (cancon<7:5>). error recog- nition mode is requested through the rxm bits of the receive buffer register(s). entry into a mode is acknowledged by monitoring the opmode bits. when changing modes, the mode will not actually change until all pending message transmissions are complete. because of this, the user must verify that the device has actually changed into the requested mode before further operations are executed. 23.3.1 configuration mode the can module has to be initialized before the activation. this is only possible if the module is in the configuration mode. the configuration mode is requested by setting the reqop2 bit. only when the status bit, opmode2, has a high level can the initial- ization be performed. afterwards, the configuration registers, the acceptance mask registers and the acceptance filter registers can be written. the module is activated by setting the reqop control bits to zero. the module will protect the user from accidentally violating the can protocol through programming errors. all registers which control the configuration of the module can not be modified while the module is on- line. the can module will not be allowed to enter the configuration mode while a transmission or reception is taking place. the configuration mode serves as a lock to protect the following registers:  configuration registers  functional mode selection registers  bit timing registers  identifier acceptance filter registers  identifier acceptance mask registers  filter and mask control registers  mask selection registers in the configuration mode, the module will not transmit or receive. the error counters are cleared and the interrupt flags remain unchanged. the programmer will have access to configuration registers that are access restricted in other modes. 23.3.2 disable mode in disable mode, the module will not transmit or receive. the module has the ability to set the wakif bit due to bus activity; however, any pending interrupts will remain and the error counters will retain their value. if the reqop<2:0> bits are set to ? 001 ?, the module will enter the module disable mode. this mode is similar to disabling other peripheral modules by turning off the module enables. this causes the module internal clock to stop unless the module is active (i.e., receiving or transmitting a message). if the module is active, the module will wait for 11 recessive bits on the can bus, detect that condition as an idle bus, then accept the module disable command. opmode<2:0> = 001 indicates whether the module successfully went into the module disable mode. the wakif interrupt is the only module interrupt that is still active in the disable mode. if the wakdis is cleared and wakie is set, the processor will receive an interrupt whenever the module detects recessive to dominant transition. on wake-up, the module will auto- matically be set to the previous mode of operation. for example, if the module was switched from normal to disable mode on bus activity wake-up, the module will automatically enter into normal mode and the first mes- sage that caused the module to wake-up is lost. the module will not generate any error frame. firmware logic must detect this condition and make sure that retransmission is requested. if the processor receives a wake-up interrupt while it is sleeping, more than one message may get lost. the actual number of messages lost would depend on the processor oscillator start-up time and incoming message bit rate. the i/o pins will revert to normal i/o function when the module is in the disable mode. 23.3.3 normal mode this is the standard operating mode of the pic18f2585/2680/4585/4680 devices. in this mode, the device actively monitors all bus messages and gen- erates acknowledge bits, error frames, etc. this is also the only mode in which the pic18f2585/2680/4585/ 4680 devices will transmit messages over the can bus.
? 2004 microchip technology inc. preliminary ds39625b-page 325 pic18f2585/2680/4585/4680 23.3.4 listen only mode listen only mode provides a means for the pic18f2585/2680/4585/4680 devices to receive all messages, including messages with errors. this mode can be used for bus monitor applications or for detecting the baud rate in ?hot plugging? situations. for auto-baud detection, it is necessary that there are at least two other nodes which are communicating with each other. the baud rate can be detected empirically by testing different values until valid messages are received. the listen only mode is a silent mode, meaning no messages will be transmitted while in this state, including error flags or acknowledge signals. the filters and masks can be used to allow only particular messages to be loaded into the receive registers or the filter masks can be set to all zeros to allow a message with any identifier to pass. the error counters are reset and deactivated in this state. the listen only mode is activated by setting the mode request bits in the cancon register. 23.3.5 loopback mode this mode will allow internal transmission of messages from the transmit buffers to the receive buffers without actually transmitting messages on the can bus. this mode can be used in system development and testing. in this mode, the ack bit is ignored and the device will allow incoming messages from itself, just as if they were coming from another node. the loopback mode is a silent mode, meaning no messages will be transmitted while in this state, including error flags or acknowledge signals. the txcan pin will revert to port i/o while the device is in this mode. the filters and masks can be used to allow only particular messages to be loaded into the receive registers. the masks can be set to all zeros to provide a mode that accepts all messages. the loopback mode is activated by setting the mode request bits in the cancon register. 23.3.6 error recognition mode the module can be set to ignore all errors and receive any message. in functional mode 0, the error recogni- tion mode is activated by setting the rxm<1:0> bits in the rxbncon registers to ? 11 ?. in this mode, the data which is in the message assembly buffer until the error time, is copied in the receive buffer and can be read via the cpu interface. 23.4 ecan module functional modes in addition to can modes of operation, the ecan mod- ule offers a total of 3 functional modes. each of these modes are identified as mode 0, mode 1 and mode 2. 23.4.1 mode 0 ? legacy mode mode 0 is designed to be fully compatible with can modules used in pic18cxx8 and pic18fxx8 devices. this is the default mode of operation on all reset conditions. as a result, module code written for the pic18xx8 can module may be used on the ecan module without any code changes. the following is the list of resources available in mode 0:  three transmit buffers: txb0, txb1 and txb2  two receive buffers: rxb0 and rxb1  two acceptance masks, one for each receive buffer: rxm0, rxm1  six acceptance filters, 2 for rxb0 and 4 for rxb1: rxf0, rxf1, rxf2, rxf3, rxf4, rxf5 23.4.2 mode 1 ? enhanced legacy mode mode 1 is similar to mode 0, with the exception that more resources are available in mode 1. there are 16 acceptance filters and two acceptance mask registers. acceptance filter 15 can be used as either an accep- tance filter or an acceptance mask register. in addition to three transmit and two receive buffers, there are six more message buffers. one or more of these additional buffers can be programmed as transmit or receive buff- ers. these additional buffers can also be programmed to automatically handle rtr messages. fourteen of sixteen acceptance filter registers can be dynamically associated to any receive buffer and acceptance mask register. one can use this capability to associate more than one filter to any one buffer. when a receive buffer is programmed to use standard identifier messages, part of the full acceptance filter register can be used as a data byte filter. the length of the data byte filter is programmable from 0 to 18 bits. this functionality simplifies implementation of high-level protocols, such as the devicenet protocol. the following is the list of resources available in mode 1:  three transmit buffers: txb0, txb1 and txb2  two receive buffers: rxb0 and rxb1  six buffers programmable as tx or rx: b0-b5  automatic rtr handling on b0-b5  sixteen dynamically assigned acceptance filters: rxf0-rxf15  two dedicated acceptance mask registers; rxf15 programmable as third mask: rxm0-rxm1, rxf15  programmable data filter on standard identifier messages: sdflc
pic18f2585/2680/4585/4680 ds39625b-page 326 preliminary ? 2004 microchip technology inc. 23.4.3 mode 2 ? enhanced fifo mode in mode 2, two or more receive buffers are used to form the receive fifo (first in, first out) buffer. there is no one-to-one relationship between the receive buffer and acceptance filter registers. any filter that is enabled and linked to any fifo receive buffer can generate acceptance and cause fifo to be updated. fifo length is user programmable, from 2-8 buffers deep. fifo length is determined by the very first programmable buffer that is configured as a transmit buffer. for example, if buffer 2 (b2) is programmed as a transmit buffer, fifo consists of rxb0, rxb1, b0 and b1 ? creating a fifo length of 4. if all program- mable buffers are configured as receive buffers, fifo will have the maximum length of 8. the following is the list of resources available in mode 2:  three transmit buffers: txb0, txb1 and txb2  two receive buffers: rxb0 and rxb1  six buffers programmable as tx or rx; receive buffers form fifo: b0-b5  automatic rtr handling on b0-b5  sixteen acceptance filters: rxf0-rxf15  two dedicated acceptance mask registers; rxf15 programmable as third mask: rxm0-rxm1, rxf15  programmable data filter on standard identifier messages: sdflc, useful for devicenet protocol 23.5 can message buffers 23.5.1 dedicated transmit buffers the pic18f2585/2680/4585/4680 devices implement three dedicated transmit buffers ? txb0, txb1 and txb2. each of these buffers occupies 14 bytes of sram and are mapped into the sfr memory map. these are the only transmit buffers available in mode 0. mode 1 and 2 may access these and other additional buffers. each transmit buffer contains one control register (txbncon), four identifier registers (txbnsidl, txbnsidh, txbneidl, txbneidh), one data length count register (txbndlc) and eight data byte registers (txbndm). 23.5.2 dedicated receive buffers the pic18f2585/2680/4585/4680 devices implement two dedicated receive buffers ? rxb0 and rxb1. each of these buffers occupies 14 bytes of sram and are mapped into sfr memory map. these are the only receive buffers available in mode 0. mode 1 and 2 may access these and other additional buffers. each receive buffer contains one control register (rxbncon), four identifier registers (rxbnsidl, rxbnsidh, rxbneidl, rxbneidh), one data length count register (rxbndlc) and eight data byte registers (rxbndm). there is also a separate message assembly buffer (mab) which acts as an additional receive buffer. mab is always committed to receiving the next message from the bus and is not directly accessible to user firm- ware. the mab assembles all incoming messages one by one. a message is transferred to appropriate receive buffers only if the corresponding acceptance filter criteria is met. 23.5.3 programmable transmit/ receive buffers the ecan module implements six new buffers: b0-b5. these buffers are individually programmable as either transmit or receive buffers. these buffers are available only in mode 1 and 2. as with dedicated transmit and receive buffers, each of these programmable buffers occupies 14 bytes of sram and are mapped into sfr memory map. each buffer contains one control register (bncon), four identifier registers (bnsidl, bnsidh, bneidl, bneidh), one data length count register (bndlc) and eight data byte registers (bndm). each of these regis- ters contains two sets of control bits. depending on whether the buffer is configured as transmit or receive, one would use the corresponding control bit set. by default, all buffers are configured as receive buffers. each buffer can be individually configured as a transmit or receive buffer by setting the corresponding txenn bit in the bsel0 register. when configured as transmit buffers, user firmware may access transmit buffers in any order similar to accessing dedicated transmit buffers. in receive config- uration with mode 1 enabled, user firmware may also access receive buffers in any order required. but in mode 2, all receive buffers are combined to form a sin- gle fifo. actual fifo length is programmable by user firmware. access to fifo must be done through the fifo pointer bits (fp<4:0>) in the cancon register. it must be noted that there is no hardware protection against out of order fifo reads.
? 2004 microchip technology inc. preliminary ds39625b-page 327 pic18f2585/2680/4585/4680 23.5.4 programmable auto-rtr buffers in mode 1 and 2, any of six programmable transmit/ receive buffers may be programmed to automatically respond to predefined rtr messages without user firmware intervention. automatic rtr handling is enabled by setting the txnen bit in the bsel0 register and the rtren bit in the bncon register. after this setup, when an rtr request is received, the txreq bit is automatically set and the current buffer content is automatically queued for transmission as a rtr response. as with all transmit buffers, once the txreq bit is set, buffer registers become read-only and any writes to them will be ignored. the following outlines the steps required to automatically handle rtr messages: 1. set buffer to transmit mode by setting txnen bit to ? 1 ? in bsel0 register. 2. at least one acceptance filter must be associated with this buffer and preloaded with expected rtr identifier. 3. bit rtren in bncon register must be set to ? 1 ? . 4. buffer must be preloaded with the data to be sent as a rtr response. normally, user firmware will keep buffer data registers up to date. if firmware attempts to update the buffer while an automatic rtr response is in the process of transmission, all writes to buffers are ignored. 23.6 can message transmission 23.6.1 initiating transmission for the mcu to have write access to the message buffer, the txreq bit must be clear, indicating that the message buffer is clear of any pending message to be transmitted. at a minimum, the sidh, sidl and dlc registers must be loaded. if data bytes are present in the message, the data registers must also be loaded. if the message is to use extended identifiers, the eidh:eidl registers must also be loaded and the exide bit set. to initiate message transmission, the txreq bit must be set for each buffer to be transmitted. when txreq is set, the txabt, txlarb and txerr bits will be cleared. to successfully complete the transmission, there must be at least one node with matching baud rate on the network. setting the txreq bit does not initiate a message transmission; it merely flags a message buffer as ready for transmission. transmission will start when the device detects that the bus is available. the device will then begin transmission of the highest priority message that is ready. when the transmission has completed successfully, the txreq bit will be cleared, the txbnif bit will be set and an interrupt will be generated if the txbnie bit is set. if the message transmission fails, the txreq will remain set, indicating that the message is still pending for trans- mission and one of the following condition flags will be set. if the message started to transmit but encountered an error condition, the txerr and the irxif bits will be set and an interrupt will be generated. if the message lost arbitration, the txlarb bit will be set. 23.6.2 aborting transmission the mcu can request to abort a message by clearing the txreq bit associated with the corresponding message buffer (txbncon<3> or bncon<3>). set- ting the abat bit (cancon<4>) will request an abort of all pending messages. if the message has not yet started transmission, or if the message started but is interrupted by loss of arbitration or an error, the abort will be processed. the abort is indicated when the module sets the txabt bit for the corresponding buffer (txbncon<6> or bncon<6>). if the message has started to transmit, it will attempt to transmit the current message fully. if the current message is transmitted fully and is not lost to arbitration or an error, the txabt bit will not be set because the message was transmit- ted successfully. likewise, if a message is being trans- mitted during an abort request and the message is lost to arbitration or an error, the message will not be retransmitted and the txabt bit will be set, indicating that the message was successfully aborted. once an abort is requested by setting the abat or txabt bits, it cannot be cleared to cancel the abort request. only can module hardware or a por condition can clear it.
pic18f2585/2680/4585/4680 ds39625b-page 328 preliminary ? 2004 microchip technology inc. 23.6.3 transmit priority transmit priority is a prioritization within the pic18f2585/2680/4585/4680 devices of the pending transmittable messages. this is independent from and not related to any prioritization implicit in the message arbitration scheme built into the can protocol. prior to sending the sof, the priority of all buffers that are queued for transmission is compared. the transmit buffer with the highest priority will be sent first. if two buffers have the same priority setting, the buffer with the highest buffer number will be sent first. there are four levels of transmit priority. if txp bits for a particular message buffer are set to ? 11 ?, that buffer has the high- est possible priority. if txp bits for a particular message buffer are set to ? 00 ?, that buffer has the lowest possible priority. figure 23-2: transmit buffers txreq txb0 txabt txlarb txerr txb0if message message queue control transmit byte sequencer txreq txb1 txabt txlarb txerr txb1if message txreq txb2 txabt txlarb txerr txb2if message message txb2if txreq txabt txlarb txerr txb3 - txb8
? 2004 microchip technology inc. preliminary ds39625b-page 329 pic18f2585/2680/4585/4680 23.7 message reception 23.7.1 receiving a message of all receive buffers, the mab is always committed to receiving the next message from the bus. the mcu can access one buffer while the other buffer is available for message reception or holding a previously received message. when a message is moved into either of the receive buffers, the associated rxful bit is set. this bit must be cleared by the mcu when it has completed process- ing the message in the buffer in order to allow a new message to be received into the buffer. this bit provides a positive lockout to ensure that the firmware has finished with the message before the module attempts to load a new message into the receive buffer. if the receive interrupt is enabled, an interrupt will be generated to indicate that a valid message has been received. once a message is loaded into any matching buffer, user firmware may determine exactly what filter caused this reception by checking the filter hit bits in the rxbncon or bncon registers. in mode 0, filhit<3:0> of rxbncon serve as filter hit bits. in mode 1 and 2, filhit<4:0> of bncon serves as filter hit bits. the same registers also indicate whether the current message is an rtr frame or not. a received message is considered a standard identifier message if the exid bit in the rxbnsidl or the bnsidl register is cleared. conversely, a set exid bit indicates an extended identifier message. if the received message is a standard identifier message, user firmware needs to read the sidl and sidh registers. in the case of an extended identifier message, firmware should read the sidl, sidh, eidl and eidh registers. if the rxbndlc or bndlc register contain non-zero data count, user firmware should also read the corresponding number of data bytes by accessing the rxbndm or the bndm registers. when a received message is an rtr and if the current buffer is not configured for automatic rtr handling, user firmware must take appropriate action and respond manually. each receive buffer contains rxm bits to set special receive modes. in mode 0, rxm<1:0> bits in rxbncon define a total of four receive modes. in mode 1 and 2, rxm1 bit, in combination with the exid mask and filter bit, define the same four receive modes. normally, these bits are set to ? 00 ? to enable reception of all valid messages as determined by the appropriate acceptance filters. in this case, the deter- mination of whether or not to receive standard or extended messages is determined by the exide bit in the acceptance filter register. in mode 0, if the rxm bits are set to ? 01 ? or ? 10 ?, the receiver will accept only messages with standard or extended identifiers, respectively. if an acceptance filter has the exide bit set such that it does not correspond with the rxm mode, that acceptance filter is rendered useless. in mode 1 and 2, setting exid in the sidl mask register will ensure that only standard or extended identifiers are received. these two modes of rxm bits can be used in systems where it is known that only standard or extended messages will be on the bus. if the rxm bits are set to ? 11 ? (rxm1 = 1 in mode 1 and 2), the buffer will receive all messages regardless of the values of the acceptance filters. also, if a message has an error before the end of frame, that portion of the message assembled in the mab before the error frame will be loaded into the buffer. this mode may serve as a valuable debugging tool for a given can network. it should not be used in an actual system environment as the actual system will always have some bus errors and all nodes on the bus are expected to ignore them. in mode 1 and 2, when a programmable buffer is configured as a transmit buffer and one or more acceptance filters are associated with it, all incoming messages matching this acceptance filter criteria will be discarded. to avoid this scenario, user firmware must make sure that there are no acceptance filters associated with a buffer configured as a transmit buffer. 23.7.2 receive priority when in mode 0, rxb0 is the higher priority buffer and has two message acceptance filters associated with it. rxb1 is the lower priority buffer and has four acceptance filters associated with it. the lower number of acceptance filters makes the match on rxb0 more restrictive and implies a higher priority for that buffer. additionally, the rxb0con register can be configured such that if rxb0 contains a valid message and another valid message is received, an overflow error will not occur and the new message will be moved into rxb1 regardless of the acceptance criteria of rxb1. there are also two programmable acceptance filter masks available, one for each receive buffer (see section 23.5 ?can message buffers? ). in mode 1 and 2, there are a total of 16 acceptance fil- ters available and each can be dynamically assigned to any of the receive buffers. a buffer with a lower number has higher priority. given this, if an incoming message matches with two or more receive buffer acceptance criteria, the buffer with the lower number will be loaded with that message. note: the entire contents of the mab are moved into the receive buffer once a message is accepted. this means that regardless of the type of identifier (standard or extended) and the number of data bytes received, the entire receive buffer is over- written with the mab contents. therefore, the contents of all registers in the buffer must be assumed to have been modified when any message is received.
pic18f2585/2680/4585/4680 ds39625b-page 330 preliminary ? 2004 microchip technology inc. 23.7.3 enhanced fifo mode when configured for mode 2, two of the dedicated receive buffers in combination with one or more programmable transmit/receive buffers, are used to create a maximum of an 8 buffer deep fifo buffer. in this mode, there is no direct correlation between filters and receive buffer registers. any filter that has been enabled can generate an acceptance. when a message has been accepted, it is stored in the next available receive buffer register and an internal write pointer is incremented. the fifo can be a maximum of 8 buffers deep. the entire fifo must consist of contig- uous receive buffers. the fifo head begins at rxb0 buffer and its tail spans toward b5. the maximum length of the fifo is limited by the presence or absence of the first transmit buffer starting from b0. if a buffer is configured as a transmit buffer, the fifo length is reduced accordingly. for instance, if b3 is configured as a transmit buffer, the actual fifo will consist of rxb0, rxb1, b0, b1 and b2, a total of 5 buffers. if b0 is configured as a transmit buffer, the fifo length will be 2. if none of the programmable buffers are configured as a transmit buffer, the fifo will be 8 buffers deep. a system that requires more transmit buffers should try to locate transmit buffers at the very end of b0-b5 buffers to maximize available fifo length. when a message is received in fifo mode, the inter- rupt flag code bits (eicode<4:0>) in the canstat register will have a value of ? 10000 ?, indicating the fifo has received a message. fifo pointer bits, fp<3:0> in the cancon register, point to the buffer that contains data not yet read. the fifo pointer bits, in this sense, serve as the fifo read pointer. the user should use fp bits and read corresponding buffer data. when receive data is no longer needed, the rxful bit in the current buffer must be cleared, causing fp<3:0> to be updated by the module. to determine whether fifo is empty or not, the user may use fp<3:0> bits to access the rxful bit in the current buffer. if rxful is cleared, the fifo is consid- ered to be empty. if it is set, the fifo may contain one or more messages. in mode 2, the module also pro- vides a bit called fifo high water mark (fifowm) in the ecancon register. this bit can be used to cause an interrupt whenever the fifo contains only one or four empty buffers. the fifo high water mark interrupt can serve as an early warning to a full fifo condition. 23.7.4 time-stamping the can module can be programmed to generate a time-stamp for every message that is received. when enabled, the module generates a capture signal for ccp1, which in turn captures the value of either timer1 or timer3. this value can be used as the message time-stamp. to use the time-stamp capability, the cancap bit (ciocan<4>) must be set. this replaces the capture input for ccp1 with the signal generated from the can module. in addition, ccp1con<3:0> must be set to ? 0011 ? to enable the ccp special event trigger for can events. 23.8 message acceptance filters and masks the message acceptance filters and masks are used to determine if a message in the message assembly buffer should be loaded into any of the receive buffers. once a valid message has been received into the mab, the identifier fields of the message are compared to the filter values. if there is a match, that message will be loaded into the appropriate receive buffer. the filter masks are used to determine which bits in the identifier are examined with the filters. a truth table is shown below in table 23-2 that indicates how each bit in the identifier is compared to the masks and filters to deter- mine if a message should be loaded into a receive buffer. the mask essentially determines which bits to apply the acceptance filters to. if any mask bit is set to a zero, then that bit will automatically be accepted regardless of the filter bit. table 23-2: filter/mask truth table in mode 0, acceptance filters rxf0 and rxf1 and filter mask rxm0 are associated with rxb0. filters rxf2, rxf3, rxf4 and rxf5 and mask rxm1 are associated with rxb1. mask bit n filter bit n message identifier bit n001 accept or reject bit n 0x x accept 10 0 accept 10 1 reject 11 0 reject 11 1 accept legend: x = don?t care
? 2004 microchip technology inc. preliminary ds39625b-page 331 pic18f2585/2680/4585/4680 in mode 1 and 2, there are an additional 10 acceptance filters, rxf6-rxf15, creating a total of 16 available filters. rxf15 can be used either as an acceptance filter or acceptance mask register. each of these acceptance filters can be individually enabled or disabled by setting or clearing the rxfenn bit in the rxfconn register. any of these 16 acceptance filters can be dynamically associated with any of the receive buffers. actual association is made by setting appropri- ate bits in the rxfbconn register. each rxfbconn register contains a nibble for each filter. this nibble can be used to associate a specific filter to any of available receive buffers. user firmware may associate more than one filter to any one specific receive buffer. in addition to dynamic filter to buffer association, in mode 1 and 2, each filter can also be dynamically asso- ciated to available acceptance mask registers. the filn_m bits in the mseln register can be used to link a specific acceptance filter to an acceptance mask reg- ister. as with filter to buffer association, one can also associate more than one mask to a specific acceptance filter. when a filter matches and a message is loaded into the receive buffer, the filter number that enabled the mes- sage reception is loaded into the filhit bit(s). in mode 0 for rxb1, the rxb1con register contains the filhit<2:0> bits. they are coded as follows:  101 = acceptance filter 5 (rxf5)  100 = acceptance filter 4 (rxf4)  011 = acceptance filter 3 (rxf3)  010 = acceptance filter 2 (rxf2)  001 = acceptance filter 1 (rxf1)  000 = acceptance filter 0 (rxf0) the coding of the rxb0dben bit enables these three bits to be used similarly to the filhit bits and to distinguish a hit on filter rxf0 and rxf1, in either rxb0 or after a rollover into rxb1.  111 = acceptance filter 1 (rxf1)  110 = acceptance filter 0 (rxf0)  001 = acceptance filter 1 (rxf1)  000 = acceptance filter 0 (rxf0) if the rxb0dben bit is clear, there are six codes corresponding to the six filters. if the rxb0dben bit is set, there are six codes corresponding to the six filters, plus two additional codes corresponding to rxf0 and rxf1 filters, that rollover into rxb1. in mode 1 and 2, each buffer control register contains 5 bits of filter hit bits (filhit<4:0>). a binary value of ? 0 ? indicates a hit from rxf0 and 15 indicates rxf15. if more than one acceptance filter matches, the filhit bits will encode the binary value of the lowest num- bered filter that matched. in other words, if filter rxf2 and filter rxf4 match, filhit will be loaded with the value for rxf2. this essentially prioritizes the acceptance filters with a lower number filter having higher priority. messages are compared to filters in ascending order of filter number. the mask and filter registers can only be modified when the pic18f2585/2680/4585/4680 devices are in configuration mode. figure 23-3: message acceptance mask and filter operation note: ? 000 ? and ? 001 ? can only occur if the rxb0dben bit is set in the rxb0con register, allowing rxb0 messages to rollover into rxb1. acceptance filter register acceptance mask register rxrqst message assembly buffer rxfn 0 rxfn 1 rxfn n rxmn 0 rxmn 1 rxmn n identifier
pic18f2585/2680/4585/4680 ds39625b-page 332 preliminary ? 2004 microchip technology inc. 23.9 baud rate setting all nodes on a given can bus must have the same nominal bit rate. the can protocol uses non-return- to-zero (nrz) coding which does not encode a clock within the data stream. therefore, the receive clock must be recovered by the receiving nodes and synchronized to the transmitter?s clock. as oscillators and transmission time may vary from node to node, the receiver must have some type of phase lock loop (pll) synchronized to data transmis- sion edges to synchronize and maintain the receiver clock. since the data is nrz coded, it is necessary to include bit stuffing to ensure that an edge occurs at least every six bit times to maintain the digital phase lock loop (dpll) synchronization. the bit timing of the pic18f2585/2680/4585/4680 is implemented using a dpll that is configured to syn- chronize to the incoming data and provides the nominal timing for the transmitted data. the dpll breaks each bit time into multiple segments made up of minimal periods of time called the time quanta (t q ). bus timing functions executed within the bit time frame, such as synchronization to the local oscillator, network transmission delay compensation and sample point positioning, are defined by the programmable bit timing logic of the dpll. all devices on the can bus must use the same bit rate. however, all devices are not required to have the same master oscillator clock frequency. for the different clock frequencies of the individual devices, the bit rate has to be adjusted by appropriately setting the baud rate prescaler and number of time quanta in each segment. the nominal bit rate is the number of bits transmitted per second, assuming an ideal transmitter with an ideal oscillator, in the absence of resynchronization. the nominal bit rate is defined to be a maximum of 1 mb/s. the nominal bit time is defined as: equation 23-1: the nominal bit time can be thought of as being divided into separate, non-overlapping time segments. these segments (figure 23-4) include:  synchronization segment (sync_seg)  propagation time segment (prop_seg)  phase buffer segment 1 (phase_seg1)  phase buffer segment 2 (phase_seg2) the time segments (and thus the nominal bit time) are in turn made up of integer units of time called time quanta or t q (see figure 23-4). by definition, the nominal bit time is programmable from a minimum of 8 t q to a maximum of 25 t q . also by definition, the minimum nominal bit time is 1 s, corresponding to a maximum 1 mb/s rate. the actual duration is given by the following relationship. equation 23-2: the time quantum is a fixed unit derived from the oscillator period. it is also defined by the programmable baud rate prescaler, with integer values from 1 to 64, in addition to a fixed divide-by-two for clock generation. mathematically, this is: equation 23-3: where f osc is the clock frequency, t osc is the corresponding oscillator period and brp is an integer (0 through 63) represented by the binary values of brgcon1<5:0>. the equation above refers to the effective clock frequency used by the microcontroller. if, for example, a 10 mhz crystal in hs mode is used, then the f osc = 10 mhz and t osc = 100 ns. if the same 10 mhz crystal is used in hs-pll mode, then the effective frequency is f osc = 40 mhz and t osc =25ns. figure 23-4: bit time partitioning t bit = 1/nominal bit rate nominal bit time= t q * (sync_seg + prop_seg + phase_seg1 + phase_seg2) t q ( s) = (2 * (brp + 1))/f osc (mhz) or t q ( s) = (2 * (brp + 1)) * t osc ( s) input sync propagation segment phase segment 1 phase segment 2 sample point t q nominal bit time bit time intervals signal segment sync
? 2004 microchip technology inc. preliminary ds39625b-page 333 pic18f2585/2680/4585/4680 23.9.1 external clock, internal clock and measurable jitter in hs-pll based oscillators the microcontroller clock frequency generated from a pll circuit is subject to a jitter, also defined as phase jitter or phase skew. for its pic18 enhanced micro- controllers, microchip specifies phase jitter ( p jitter ) as being 2% (gaussian distribution, within 3 standard deviations, see parameter f13 in table 27-7) and total jitter ( t jitter ) as being 2 * p jitter . the can protocol uses a bit-stuffing technique that inserts a bit of a given polarity following five bits with the opposite polarity. this gives a total of 10 bits transmit- ted without re-synchronization (compensation for jitter or phase error). given the random nature of the jitter error added, it can be shown that the total error caused by the jitter tends to cancel itself over time. for a period of 10 bits, it is necessary to add only two jitter intervals to correct for jitter-induced error: one interval in the beginning of the 10-bit period and another at the end. the overall effect is shown in figure 23-5. figure 23-5: effects of phase jitter on the microcontroller clock and can bit time once these considerations are taken into account, it is possible to show that the relation between the jitter and the total frequency error can be defined as: where jitter is expressed in terms of time and nbt is the nominal bit time. for example, assume a can bit rate of 125 kb/s, which gives an nbt of 8 s. for a 16 mhz clock generated from a 4x pll, the jitter at this clock frequency is: and resultant frequency error is: nominal clock clock with jitter can bit time phase skew (jitter) can bit jitter with jitter ? f t jitter 10 nbt ----------------------- - 2 p jitter 10 nbt ----------------------- - = = 2% 1 16 mhz ------------------- 0.02 16 6 10 ----------------- 1 . 2 5 n s == 21.25 9 ? 10 () 10 8 6 ? 10 () -------------------------------------- - 3.125 5 ? 10 0.0031% = =
pic18f2585/2680/4585/4680 ds39625b-page 334 preliminary ? 2004 microchip technology inc. table 23-3 shows the relation between the clock generated by the pll and the frequency error from jitter (measured jitter-induced error of 2%, gaussian distribu- tion, within 3 standard deviations), as a percentage of the nominal clock frequency. this is clearly smaller than the expected drift of a crystal oscillator, typically specified at 100 ppm or 0.01%. if we add jitter to oscillator drift, we have a total frequency drift of 0.0132%. the total oscillator frequency errors for common clock frequencies and bit rates, including both drift and jitter, are shown in table 23-4. table 23-3: frequency error from jitter at various pll generated clock speeds table 23-4: total frequency error at various pll generated clock speeds (100 ppm oscillator drift, including error from jitter) pll output p jitter t jitter frequency error at various nominal bit times (bit rates) 8 s (125 kb/s) 4 s (250 kb/s) 2 s (500 kb/s) 1 s (1 mb/s) 40 mhz 0.5 ns 1 ns 0.00125% 0.00250% 0.005% 0.01% 24 mhz 0.83 ns 1.67 ns 0.00209% 0.00418% 0.008% 0.017% 16 mhz 1.25 ns 2.5 ns 0.00313% 0.00625% 0.013% 0.025% nominal pll output frequency error at various nominal bit times (bit rates) 8 s (125 kb/s) 4 s (250 kb/s) 2 s (500 kb/s) 1 s (1 mb/s) 40 mhz 0.01125% 0.01250% 0.015% 0.02% 24 mhz 0.01209% 0.01418% 0.018% 0.027% 16 mhz 0.01313% 0.01625% 0.023% 0.035%
? 2004 microchip technology inc. preliminary ds39625b-page 335 pic18f2585/2680/4585/4680 23.9.2 time quanta as already mentioned, the time quanta is a fixed unit derived from the oscillator period and baud rate prescaler. its relationship to t bit and the nominal bit rate is shown in example 23-6. example 23-6: calculating t q , nominal bit rate and nominal bit time the frequencies of the oscillators in the different nodes must be coordinated in order to provide a system wide specified nominal bit time. this means that all oscilla- tors must have a t osc that is an integral divisor of t q . it should also be noted that although the number of t q is programmable from 4 to 25, the usable minimum is 8t q . there is no assurance that a bit time of less than 8 t q in length will operate correctly. 23.9.3 synchronization segment this part of the bit time is used to synchronize the various can nodes on the bus. the edge of the input signal is expected to occur during the sync segment. the duration is 1 t q . 23.9.4 propagation segment this part of the bit time is used to compensate for phys- ical delay times within the network. these delay times consist of the signal propagation time on the bus line and the internal delay time of the nodes. the length of the propagation segment can be programmed from 1t q to 8 t q by setting the prseg2:prseg0 bits. 23.9.5 phase buffer segments the phase buffer segments are used to optimally locate the sampling point of the received bit within the nominal bit time. the sampling point occurs between phase segment 1 and phase segment 2. these segments can be lengthened or shortened by the resynchronization process. the end of phase segment 1 determines the sampling point within a bit time. phase segment 1 is programmable from 1 t q to 8 t q in duration. phase segment 2 provides delay before the next transmitted data transition and is also programmable from 1 t q to 8 t q in duration. however, due to ipt requirements, the actual minimum length of phase segment 2 is 2 t q , or it may be defined to be equal to the greater of phase segment 1 or the information processing time (ipt). the sampling point should be as late as possible or approximately 80% of the bit time. 23.9.6 sample point the sample point is the point of time at which the bus level is read and the value of the received bit is determined. the sampling point occurs at the end of phase segment 1. if the bit timing is slow and contains many t q , it is possible to specify multiple sampling of the bus line at the sample point. the value of the received bit is determined to be the value of the major- ity decision of three values. the three samples are taken at the sample point and twice before, with a time of t q /2 between each sample. 23.9.7 information processing time the information processing time (ipt) is the time segment starting at the sample point that is reserved for calculation of the subsequent bit level. the can specification defines this time to be less than or equal to 2 t q . the pic18f2585/2680/4585/4680 devices define this time to be 2 t q . thus, phase segment 2 must be at least 2 t q long. t q ( s) = (2 * (brp + 1))/f osc (mhz) t bit ( s) = t q ( s) * number of t q per bit interval nominal bit rate (bits/s) = 1/t bit this frequency (f osc ) refers to the effective frequency used. if, for example, a 10 mhz externa l signal is used along with a pll, then the effective frequency will be 4 x 10 mhz which equals 40 mhz . case 1: for f osc = 16 mhz, brp<5:0> = 00h and nominal bit time = 8 t q : t q = (2 * 1)/16 = 0.125 s (125 ns) t bit = 8 * 0.125 = 1 s (10 -6 s) nominal bit rate = 1/10 -6 = 10 6 bits/s (1 mb/s) case 2: for f osc = 20 mhz, brp<5:0> = 01h and nominal bit time = 8 t q : t q = (2 * 2)/20 = 0.2 s (200 ns) t bit = 8 * 0.2 = 1.6 s (1.6 * 10 -6 s) nominal bit rate = 1/1.6 * 10 -6 s = 625,000 bits/s (625 kb/s) case 3: for f osc = 25 mhz, brp<5:0> = 3fh and nominal bit time = 25 t q : t q = (2 * 64)/25 = 5.12 s t bit = 25 * 5.12 = 128 s (1.28 * 10 -4 s) nominal bit rate = 1/1.28 * 10 -4 = 7813 bits/s (7.8 kb/s)
pic18f2585/2680/4585/4680 ds39625b-page 336 preliminary ? 2004 microchip technology inc. 23.10 synchronization to compensate for phase shifts between the oscillator frequencies of each of the nodes on the bus, each can controller must be able to synchronize to the relevant signal edge of the incoming signal. when an edge in the transmitted data is detected, the logic will compare the location of the edge to the expected time (sync_seg). the circuit will then adjust the values of phase segment 1 and phase segment 2 as necessary. there are two mechanisms used for synchronization. 23.10.1 hard synchronization hard synchronization is only done when there is a recessive to dominant edge during a bus idle condition, indicating the start of a message. after hard synchroni- zation, the bit time counters are restarted with sync_seg. hard synchronization forces the edge which has occurred to lie within the synchronization segment of the restarted bit time. due to the rules of synchronization, if a hard synchronization occurs, there will not be a resynchronization within that bit time. 23.10.2 resynchronization as a result of resynchronization, phase segment 1 may be lengthened or phase segment 2 may be short- ened. the amount of lengthening or shortening of the phase buffer segments has an upper bound given by the synchronization jump width (sjw). the value of the sjw will be added to phase segment 1 (see figure 23-6) or subtracted from phase segment 2 (see figure 23-7). the sjw is programmable between 1 t q and 4 t q . clocking information will only be derived from recessive to dominant transitions. the property, that only a fixed maximum number of successive bits have the same value, ensures resynchronization to the bit stream during a frame. the phase error of an edge is given by the position of the edge relative to sync_seg, measured in t q . the phase error is defined in magnitude of t q as follows:  e = 0 if the edge lies within sync_seg.  e > 0 if the edge lies before the sample point.  e < 0 if the edge lies after the sample point of the previous bit. if the magnitude of the phase error is less than, or equal to, the programmed value of the synchronization jump width, the effect of a resynchronization is the same as that of a hard synchronization. if the magnitude of the phase error is larger than the synchronization jump width and if the phase error is positive, then phase segment 1 is lengthened by an amount equal to the synchronization jump width. if the magnitude of the phase error is larger than the resynchronization jump width and if the phase error is negative, then phase segment 2 is shortened by an amount equal to the synchronization jump width. 23.10.3 synchronization rules  only one synchronization within one bit time is allowed.  an edge will be used for synchronization only if the value detected at the previous sample point (previously read bus value) differs from the bus value immediately after the edge.  all other recessive to dominant edges fulfilling rules 1 and 2 will be used for resynchronization, with the exception that a node transmitting a dominant bit will not perform a resynchronization as a result of a recessive to dominant edge with a positive phase error.
? 2004 microchip technology inc. preliminary ds39625b-page 337 pic18f2585/2680/4585/4680 figure 23-6: lengthening a bit period (adding sjw to phase segment 1) figure 23-7: shortening a bit period (subtracting sjw from phase segment 2) 23.11 programming time segments some requirements for programming of the time segments:  prop_seg + phase_seg 1 phase_seg 2  phase_seg 2 sync jump width. for example, assume that a 125 khz can baud rate is desired, using 20 mhz for f osc . with a t osc of 50 ns, a baud rate prescaler value of 04h gives a t q of 500 ns. to obtain a nominal bit rate of 125 khz, the nominal bit time must be 8 s or 16 t q . using 1 t q for the sync_seg, 2 t q for the prop_seg and 7 t q for phase segment 1 would place the sample point at 10 t q after the transition. this leaves 6 t q for phase segment 2. by the rules above, the sync jump width could be the maximum of 4 t q . however, normally a large sjw is only necessary when the clock generation of the differ- ent nodes is inaccurate or unstable, such as using ceramic resonators. typically, an sjw of 1 is enough. 23.12 oscillator tolerance as a rule of thumb, the bit timing requirements allow ceramic resonators to be used in applications with transmission rates of up to 125 kbit/sec. for the full bus speed range of the can protocol, a quartz oscillator is required. a maximum node-to-node oscillator variation of 1.7% is allowed. input sync prop segment phase segment 1 phase segment 2 sjw sample point t q signal nominal bit length actual bit length bit time segments sync prop segment phase segment 1 phase segment 2 sjw t q sample point nominal bit length actual bit length
pic18f2585/2680/4585/4680 ds39625b-page 338 preliminary ? 2004 microchip technology inc. 23.13 bit timing configuration registers the baud rate control registers (brgcon1, brgcon2, brgcon3) control the bit timing for the can bus interface. these registers can only be modified when the pic18f2585/2680/4585/4680 devices are in configuration mode. 23.13.1 brgcon1 the brp bits control the baud rate prescaler. the sjw<1:0> bits select the synchronization jump width in terms of multiples of t q . 23.13.2 brgcon2 the prseg bits set the length of the propagation seg- ment in terms of t q . the seg1ph bits set the length of phase segment 1 in t q . the sam bit controls how many times the rxcan pin is sampled. setting this bit to a ? 1 ? causes the bus to be sampled three times: twice at t q /2 before the sample point and once at the normal sample point (which is at the end of phase segment 1). the value of the bus is determined to be the value read during at least two of the samples. if the sam bit is set to a ? 0 ?, then the rxcan pin is sampled only once at the sample point. the seg2phts bit controls how the length of phase segment 2 is determined. if this bit is set to a ? 1 ? , then the length of phase segment 2 is determined by the seg2ph bits of brgcon3. if the seg2phts bit is set to a ? 0 ?, then the length of phase segment 2 is the greater of phase segment 1 and the information processing time (which is fixed at 2 t q for the pic18f2585/2680/4585/4680). 23.13.3 brgcon3 the phseg2<2:0> bits set the length (in t q ) of phase segment 2 if the seg2phts bit is set to a ? 1 ?. if the seg2phts bit is set to a ? 0 ?, then the phseg2<2:0> bits have no effect. 23.14 error detection the can protocol provides sophisticated error detection mechanisms. the following errors can be detected. 23.14.1 crc error with the cyclic redundancy check (crc), the trans- mitter calculates special check bits for the bit sequence, from the start of a frame until the end of the data field. this crc sequence is transmitted in the crc field. the receiving node also calculates the crc sequence using the same formula and performs a comparison to the received sequence. if a mismatch is detected, a crc error has occurred and an error frame is generated. the message is repeated. 23.14.2 acknowledge error in the acknowledge field of a message, the transmitter checks if the acknowledge slot (which was sent out as a recessive bit) contains a dominant bit. if not, no other node has received the frame correctly. an acknowl- edge error has occurred, an error frame is generated and the message will have to be repeated. 23.14.3 form error if a node detects a dominant bit in one of the four segments, including end-of-frame, interframe space, acknowledge delimiter or crc delimiter, then a form error has occurred and an error frame is generated. the message is repeated. 23.14.4 bit error a bit error occurs if a transmitter sends a dominant bit and detects a recessive bit, or if it sends a recessive bit and detects a dominant bit, when monitoring the actual bus level and comparing it to the just transmitted bit. in the case where the transmitter sends a recessive bit and a dominant bit is detected during the arbitration field and the acknowledge slot, no bit error is generated because normal arbitration is occurring. 23.14.5 stuff bit error lf, between the start-of-frame and the crc delimiter, six consecutive bits with the same polarity are detected, the bit stuffing rule has been violated. a stuff bit error occurs and an error frame is generated. the message is repeated. 23.14.6 error states detected errors are made public to all other nodes via error frames. the transmission of the erroneous message is aborted and the frame is repeated as soon as possible. furthermore, each can node is in one of the three error states: ?error-active?, ?error-passive? or ?bus-off?, according to the value of the internal error counters. the error-active state is the usual state where the bus node can transmit messages and activate error frames (made of dominant bits) without any restrictions. in the error-passive state, messages and passive error frames (made of recessive bits) may be transmitted. the bus-off state makes it temporarily impossible for the station to participate in the bus communication. during this state, messages can neither be received nor transmitted. 23.14.7 error modes and error counters the pic18f2585/2680/4585/4680 devices contain two error counters: the receive error counter (rxerrcnt) and the transmit error counter (txerrcnt). the values of both counters can be read by the mcu. these counters are increment ed or decremented in accordance with the can bus specification.
? 2004 microchip technology inc. preliminary ds39625b-page 339 pic18f2585/2680/4585/4680 the pic18f2585/2680/4585/4680 devices are error- active if both error counters are below the error-passive limit of 128. they are error-passive if at least one of the error counters equals or exceeds 128. they go to bus- off if the transmit error counter equals or exceeds the bus-off limit of 256. the devices remain in this state until the bus-off recovery sequence is received. the bus-off recovery sequence consists of 128 occurrences of 11 consecutive recessive bits (see figure 23-8). note that the can module, after going bus-off, will recover back to error-active without any intervention by the mcu if the bus remains idle for 128 x 11 bit times. if this is not desired, the error interrupt service routine should address this. the current error mode of the can module can be read by the mcu via the comstat register. additionally, there is an error state warning flag bit, ewarn, which is set if at least one of the error counters equals or exceeds the error warning limit of 96. ewarn is reset if both error counters are less than the error warning limit. figure 23-8: error modes state diagram 23.15 can interrupts the module has several sources of interrupts. each of these interrupts can be individually enabled or disabled. the pir3 register contains interrupt flags. the pie3 register contains the enables for the 8 main interrupts. a special set of read-only bits in the canstat register, the icode bits, can be used in combination with a jump table for efficient handling of interrupts. all interrupts have one source, with the exception of the error interrupt and buffer interrupts in mode 1 and 2. any of the error interrupt sources can set the error interrupt flag. the source of the error interrupt can be determined by reading the communication status register, comstat. in mode 1 and 2, there are two interrupt enable/disable and flag bits ? one for all transmit buffers and the other for all receive buffers. the interrupts can be broken up into two categories: receive and transmit interrupts. the receive related interrupts are:  receive interrupts  wake-up interrupt  receiver overrun interrupt  receiver warning interrupt  receiver error-passive interrupt the transmit related interrupts are:  transmit interrupts  transmitter warning interrupt  transmitter error-passive interrupt  bus-off interrupt bus- off error - active error - passive rxerrcnt < 127 or txerrcnt < 127 rxerrcnt > 127 or txerrcnt > 127 txerrcnt > 255 128 occurrences of 11 consecutive ?recessive? bits reset
pic18f2585/2680/4585/4680 ds39625b-page 340 preliminary ? 2004 microchip technology inc. 23.15.1 interrupt code bits to simplify the interrupt handling process in user firm- ware, the ecan module encodes a special set of bits. in mode 0, these bits are icode<3:1> in the canstat register. in mode 1 and 2, these bits are eicode<4:0> in the canstat register. interrupts are internally prioritized such that the higher priority interrupts are assigned lower values. once the highest priority interrupt condition has been cleared, the code for the next highest priority inter- rupt that is pending (if any) will be reflected by the icode bits (see table 23-5). note that only those interrupt sources that have their associated interrupt enable bit set will be reflected in the icode bits. in mode 2, when a receive message interrupt occurs, the eicode bits will always consist of ? 10000 ?. user firmware may use fifo pointer bits to actually access the next available buffer. 23.15.2 transmit interrupt when the transmit interrupt is enabled, an interrupt will be generated when the associated transmit buffer becomes empty and is ready to be loaded with a new message. in mode 0, there are separate interrupt enable/disable and flag bits for each of the three dedi- cated transmit buffers. the txbnif bit will be set to indi- cate the source of the interrupt. the interrupt is cleared by the mcu, resetting the txbnif bit to a ? 0 ?. in mode 1 and 2, all transmit buffers share one interrupt enable/ disable bit and one flag bit. in mode 1 and 2, txbnie in pie3 and txbnif in pir3 indicate when a transmit buffer has completed transmission of its message. txb- nif, txbnie and txbnip in pir3, pie3 and ipr3, respectively, are not used in mode 1 and 2. individual transmit buffer interrupts can be enabled or disabled by setting or clearing txbie and bie0 register bits. when a shared interrupt occurs, user firmware must poll the txreq bit of all transmit buffers to detect the source of interrupt. 23.15.3 receive interrupt when the receive interrupt is enabled, an interrupt will be generated when a message has been successfully received and loaded into the associated receive buffer. this interrupt is activated immediately after receiving the end-of-frame (eof) field. in mode 0, the rxbnif bit is set to indicate the source of the interrupt. the interrupt is cleared by the mcu, resetting the rxbnif bit to a ? 0 ?. in mode 1 and 2, all receive buffers share rxbie, rxbif and rxbip in pie3, pir3 and ipr3, respec- tively. bits rxbnie, rxbnif and rxbnip are not used. individual receive buffer interrupts can be controlled by the txbie and bie0 registers. in mode 1, when a shared receive interrupt occurs, user firmware must poll the rxful bit of each receive buffer to detect the source of interrupt. in mode 2, a receive interrupt indicates that the new message is loaded into fifo. fifo can be read by using fifo pointer bits, fp. table 23-5: values for icode<3:1> 23.15.4 message error interrupt when an error occurs during transmission or reception of a message, the message error flag, irxif, will be set and if the irxie bit is set, an interrupt will be generated. this is intended to be used to facilitate baud rate determination when used in conjunction with listen only mode. icode <2:0> interrupt boolean expression 000 none err wak tx0 tx1 tx2 rx0 rx1 001 error err 010 txb2 err tx0 tx1 tx2 011 txb1 err tx0 tx1 100 txb0 err tx0 101 rxb1 err tx0 tx1 tx2 rx0 rx1 110 rxb0 err tx0 tx1 tx2 rx0 111 wake on interrupt err tx0 tx1 tx2 rx0 rx1 wak legend: err = errif * errie rx0 = rxb0if * rxb0ie tx0 = txb0if * txb0ie rx1 = rxb1if * rxb1ie tx1 = txb1if * txb1ie wak = wakif * wakie tx2 = txb2if * txb2ie
? 2004 microchip technology inc. preliminary ds39625b-page 341 pic18f2585/2680/4585/4680 23.15.5 bus activity wake-up interrupt when the pic18f2585/2680/4585/4680 devices are in sleep mode and the bus activity wake-up interrupt is enabled, an interrupt will be generated and the wakif bit will be set when activity is detected on the can bus. this interrupt causes the pic18f2585/2680/4585/ 4680 devices to exit sleep mode. the interrupt is reset by the mcu, clearing the wakif bit. 23.15.6 error interrupt when the error interrupt is enabled, an interrupt is generated if an overflow condition occurs or if the error state of the transmitter or receiver has changed. the error flags in comstat will indicate one of the following conditions. 23.15.6.1 receiver overflow an overflow condition occurs when the mab has assembled a valid received message (the message meets the criteria of the acceptance filters) and the receive buffer associated with the filter is not available for loading of a new message. the associated rxbnovfl bit in the comstat register will be set to indicate the overflow condition. this bit must be cleared by the mcu. 23.15.6.2 receiver warning the receive error counter has reached the mcu warning limit of 96. 23.15.6.3 transmitter warning the transmit error counter has reached the mcu warning limit of 96. 23.15.6.4 receiver bus passive the receive error counter has exceeded the error- passive limit of 127 and the device has gone to error-passive state. 23.15.6.5 transmitter bus passive the transmit error counter has exceeded the error- passive limit of 127 and the device has gone to error-passive state. 23.15.6.6 bus-off the transmit error counter has exceeded 255 and the device has gone to bus-off state. 23.15.6.7 interrupt acknowledge interrupts are directly associated with one or more status flags in the pir register. interrupts are pending as long as one of the flags is set. once an interrupt flag is set by the device, the flag can not be reset by the microcontroller until the interrupt condition is removed.
pic18f2585/2680/4585/4680 ds39625b-page 342 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 343 pic18f2585/2680/4585/4680 24.0 special features of the cpu pic18f2585/2680/4585/4680 devices include several features intended to maximize reliability and minimize cost through elimination of external components. these are:  oscillator selection  resets: - power-on reset (por) - power-up timer (pwrt) - oscillator start-up timer (ost) - brown-out reset (bor)  interrupts  watchdog timer (wdt)  fail-safe clock monitor  two-speed start-up  code protection  id locations  in-circuit serial programming the oscillator can be configured for the application depending on frequency, power, accuracy and cost. all of the options are discussed in detail in section 2.0 ?oscillator configurations? . a complete discussion of device resets and interrupts is available in previous sections of this data sheet. in addition to their power-up and oscillator start-up timers provided for resets, pic18f2585/2680/4585/ 4680 devices have a watchdog timer, which is either permanently enabled via the configuration bits or software controlled (if configured as disabled). the inclusion of an internal rc oscillator also provides the additional benefits of a fail-safe clock monitor (fscm) and two-speed start-up. fscm provides for background monitoring of the peripheral clock and automatic switchover in the event of its failure. two- speed start-up enables code to be executed almost immediately on start-up, while the primary clock source completes its start-up delays. all of these features are enabled and configured by setting the appropriate configuration register bits. 24.1 configuration bits the configuration bits can be programmed (read as ? 0 ?) or left unprogrammed (read as ? 1 ?) to select various device configurations. these bits are mapped starting at program memory location 300000h. the user will note that address 300000h is beyond the user program memory space. in fact, it belongs to the configuration memory space (300000h-3fffffh), which can only be accessed using table reads and table writes. programming the configuration registers is done in a manner similar to programming the flash memory. the wr bit in the eecon1 register starts a self-timed write to the configuration register. in normal operation mode, a tblwt instruction with the tblptr pointing to the configuration register sets up the address and the data for the configuration register write. setting the wr bit starts a long write to the configuration register. the configuration registers are written a byte at a time. to write or erase a configuration cell, a tblwt instruction can write a ? 1 ? or a ? 0 ? into the cell. for additional details on flash programming, refer to section 6.5 ?writing to flash program memory? . table 24-1: configuration bits and device ids file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 default/ unprogrammed value 300001h config1h ieso fcmen ? ? fosc3 fosc2 fosc1 fosc0 00-- 0111 300002h config2l ? ? ? borv1 borv0 boren1 boren0 pwrten ---1 1111 300003h config2h ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 wdten ---1 1111 300005h config3h mclre ? ? ? ? lpt1osc pbaden ? 1--- -01- 300006h config4l debug xinst bbsiz1 bbsiz2 ?lvp ?stvren 1000 -1-1 300008h config5l ? ? ? ? cp3 cp2 cp1 cp0 ---- 1111 300009h config5h cpd cpb ? ? ? ? ? ? 11-- ---- 30000ah config6l ? ? ? ? wrt3 wrt2 wrt1 wrt0 ---- 1111 30000bh config6h wrtd wrtb wrtc ? ? ? ? ? 111- ---- 30000ch config7l ? ? ? ? ebtr3 ebtr2 ebtr1 ebtr0 ---- 1111 30000dh config7h ?ebtrb ? ? ? ? ? ? -1-- ---- 3ffffeh devid1 dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 xxxx xxxx (1) 3fffffh devid2 dev10 dev9 dev8 dev7 dev6 dev5 dev4 dev3 0000 1100 legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition. shaded cells are unimplemented, read as ? 0 ?. note 1: see register 24-14 for devid1 values. devid regist ers are read-only and cannot be programmed by the user.
pic18f2585/2680/4585/4680 ds39625b-page 344 preliminary ? 2004 microchip technology inc. register 24-1: config1h: configuration register 1 high (byte address 300001h) r/p-0 r/p-0 u-0 u-0 r/p-0 r/p-1 r/p-1 r/p-1 ieso fcmen ? ? fosc3 fosc2 fosc1 fosc0 bit 7 bit 0 bit 7 ieso: internal/external oscillator switchover bit 1 = oscillator switchover mode enabled 0 = oscillator switchover mode disabled bit 6 fcmen: fail-safe clock monitor enable bit 1 = fail-safe clock monitor enabled 0 = fail-safe clock monitor disabled bit 5-4 unimplemented: read as ? 0 ? bit 3-0 fosc3:fosc0: oscillator selection bits 11xx = external rc oscillator, clko function on ra6 101x = external rc oscillator, clko function on ra6 1001 = internal oscillator block, clko function on ra6, port function on ra7 1000 = internal oscillator block, port function on ra6 and ra7 0111 = external rc oscillator, port function on ra6 0110 = hs oscillator, pll enabled (clock frequency = 4 x fosc1) 0101 = ec oscillator, port function on ra6 0100 = ec oscillator, clko function on ra6 0011 = external rc oscillator, clko function on ra6 0010 = hs oscillator 0001 = xt oscillator 0000 = lp oscillator legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state
? 2004 microchip technology inc. preliminary ds39625b-page 345 pic18f2585/2680/4585/4680 register 24-2: config2l: configuration register 2 low (byte address 300002h) u-0 u-0 u-0 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 ? ? ? borv1 borv0 boren1 (1) boren0 (1) pwrten (1) bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4-3 borv1:borv0: brown-out reset voltage bits 11 = v bor set to 2.1v 10 = v bor set to 2.8v 01 = v bor set to 4.3v 00 = v bor set to 4.6v bit 2-1 boren1:boren0 brown-out reset enable bits (1) 11 = brown-out reset enabled in hardware only (sboren is disabled) 10 = brown-out reset enabled in hardware only and disabled in sleep mode (sboren is disabled) 01 = brown-out reset enabled and controlled by software (sboren is enabled) 00 = brown-out reset disabled in hardware and software bit 0 pwrten : power-up timer enable bit (1) 1 = pwrt disabled 0 = pwrt enabled note 1: the power-up timer is decoupled from brown-out reset, allowing these features to be independently controlled. legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state
pic18f2585/2680/4585/4680 ds39625b-page 346 preliminary ? 2004 microchip technology inc. register 24-3: config2h: configuration register 2 high (byte address 300003h) u-0 u-0 u-0 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 wdten bit 7 bit 0 bit 7-5 unimplemented: read as ? 0 ? bit 4-1 wdtps3:wdtps0: watchdog timer postscale select bits 1111 = 1:32,768 1110 = 1:16,384 1101 = 1:8,192 1100 = 1:4,096 1011 = 1:2,048 1010 = 1:1,024 1001 = 1:512 1000 = 1:256 0111 = 1:128 0110 = 1:64 0101 = 1:32 0100 = 1:16 0011 = 1:8 0010 = 1:4 0001 = 1:2 0000 = 1:1 bit 0 wdten: watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled (control is placed on the swdten bit) legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state
? 2004 microchip technology inc. preliminary ds39625b-page 347 pic18f2585/2680/4585/4680 register 24-4: config3h: configuration register 3 high (byte address 300005h) register 24-5: config4l: configuration register 4 low (byte address 300006h) r/p-1 u-0 u-0 u-0 u-0 r/p-0 r/p-1 r/p-1 mclre ? ? ? ? lpt1osc pbaden ? bit 7 bit 0 bit 7 mclre: mclr pin enable bit 1 = mclr pin enabled; re3 input pin disabled 0 = re3 input pin enabled; mclr disabled bit 6-3 unimplemented: read as ? 0 ? bit 2 lpt1osc: low-power timer 1 oscillator enable bit 1 = timer1 configured for low-power operation 0 = timer1 configured for higher power operation bit 1 pbaden: portb a/d enable bit (affects adcon1 reset state. adcon1 controls portb<4:0> pin configuration.) 1 = portb<4:0> pins are configured as analog input channels on reset 0 = portb<4:0> pins are configured as digital i/o on reset bit 0 unimplemented: read as ? 0 ? legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state r/p-1 r/p-0 r/p-0 r/p-0 u-0 r/p-1 u-0 r/p-1 debug xinst bbsiz1 bbsiz2 ?lvp ?stvren bit 7 bit 0 bit 7 debug : background debugger enable bit 1 = background debugger disabled, rb6 and rb7 configured as general purpose i/o pins 0 = background debugger enabled, rb6 and rb7 are dedicated to in-circuit debug bit 6 xinst: extended instruction set enable bit 1 = instruction set extension and indexed addressing mode enabled 0 = instruction set extension and indexed addressing mode disabled (legacy mode) bit 5 bbsiz1: boot block size select bit 1 11 = 4k words (8 kbytes) boot block 10 = 4k words (8 kbytes) boot block bit 4 bbsiz2: boot block size select bit 0 01 = 2k words (4 kbytes) boot block 00 = 1k words (2 kbytes) boot block bit 3 unimplemented: read as ? 0 ? bit 2 lvp: single-supply icsp enable bit 1 = single-supply icsp enabled 0 = single-supply icsp disabled bit 1 unimplemented: read as ? 0 ? bit 0 stvren: stack full/underflow reset enable bit 1 = stack full/underflow will cause reset 0 = stack full/underflow will not cause reset legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state
pic18f2585/2680/4585/4680 ds39625b-page 348 preliminary ? 2004 microchip technology inc. register 24-6: config5l: configuration register 5 low (byte address 300008h) register 24-7: config5h: configuration register 5 high (byte address 300009h) u-0 u-0 u-0 u-0 r/c-1 r/c-1 r/c-1 r/c-1 ? ? ? ?cp3 (1) cp2 cp1 cp0 bit 7 bit 0 bit 7-4 unimplemented: read as ? 0 ? bit 3 cp3: code protection bit (1) 1 = block 3 (00c000-00ffffh) not code-protected 0 = block 3 (00c000-00ffffh) code-protected note 1: unimplemented in pic18fx585 devices; maintain this bit set. bit 2 cp2: code protection bit 1 = block 2 (008000-00bfffh) not code-protected 0 = block 2 (008000-00bfffh) code-protected bit 1 cp1: code protection bit 1 = block 1 (004000-007fffh) not code-protected 0 = block 1 (004000-007fffh) code-protected bit 0 cp0: code protection bit 1 = block 0 (000800-003fffh) not code-protected 0 = block 0 (000800-003fffh) code-protected legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state r/c-1 r/c-1 u-0 u-0 u-0 u-0 u-0 u-0 cpd cpb ? ? ? ? ? ? bit 7 bit 0 bit 7 cpd: data eeprom code protection bit 1 = data eeprom not code-protected 0 = data eeprom code-protected bit 6 cpb: boot block code protection bit 1 = boot block (000000-0007ffh) not code-protected 0 = boot block (000000-0007ffh) code-protected bit 5-0 unimplemented: read as ? 0 ? legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state
? 2004 microchip technology inc. preliminary ds39625b-page 349 pic18f2585/2680/4585/4680 register 24-8: config6l: configuration register 6 low (byte address 30000ah) register 24-9: config6h: co nfiguration register 6 high (byte address 30000bh) u-0 u-0 u-0 u-0 r/c-1 r/c-1 r/c-1 r/c-1 ? ? ? ?wrt3 (1) wrt2 wrt1 wrt0 bit 7 bit 0 bit 7-4 unimplemented: read as ? 0 ? bit 3 wrt3: write protection bit (1) 1 = block 3 (00c000-00ffffh) not write-protected 0 = block 3 (00c000-00ffffh) write-protected note 1: unimplemented in pic18fx585 devices; maintain this bit set. bit 2 wrt2: write protection bit 1 = block 2 (008000-00bfffh) not write-protected 0 = block 2 (008000-00bfffh) write-protected bit 1 wrt1: write protection bit 1 = block 1 (004000-007fffh) not write-protected 0 = block 1 (004000-007fffh) write-protected bit 0 wrt0: write protection bit 1 = block 0 (000800-003fffh) not write-protected 0 = block 0 (000800-003fffh) write-protected legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state r/c-1 r/c-1 r-1 u-0 u-0 u-0 u-0 u-0 wrtd wrtb wrtc (1) ? ? ? ? ? bit 7 bit 0 bit 7 wrtd: data eeprom write protection bit 1 = data eeprom not write-protected 0 = data eeprom write-protected bit 6 wrtb: boot block write protection bit 1 = boot block (000000-0007ffh) not write-protected 0 = boot block (000000-0007ffh) write-protected bit 5 wrtc: configuration register write protection bit (1) 1 = configuration registers (300000-3000ffh) not write-protected 0 = configuration registers (300000-3000ffh) write-protected note 1: this bit is read-only in normal execution mode; it can be written only in program mode. bit 4-0 unimplemented: read as ? 0 ? legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state
pic18f2585/2680/4585/4680 ds39625b-page 350 preliminary ? 2004 microchip technology inc. register 24-10: config7l: configuration register 7 low (byte address 30000ch) register 24-11: config7h: configuration register 7 high (byte address 30000dh) u-0 u-0 u-0 u-0 r/c-1 r/c-1 r/c-1 r/c-1 ? ? ? ? ebtr3 (1) ebtr2 ebtr1 ebtr0 bit 7 bit 0 bit 7-4 unimplemented: read as ? 0 ? bit 3 ebtr3: table read protection bit (1) 1 = block 3 (00c000-00ffffh) not protected from table reads executed in other blocks 0 = block 3 (00c000-00ffffh) protected from table reads executed in other blocks note 1: unimplemented in pic18fx585 devices; maintain this bit set. bit 2 ebtr2 : table read protection bit 1 = block 2 (008000-00bfffh) not protected from table reads executed in other blocks 0 = block 2 (008000-00bfffh) protected from table reads executed in other blocks bit 1 ebtr1: table read protection bit 1 = block 1 (004000-007fffh) not protected from table reads executed in other blocks 0 = block 1 (004000-007fffh) protected from table reads executed in other blocks bit 0 ebtr0: table read protection bit 1 = block 0 (000800-003fffh) not protected from table reads executed in other blocks 0 = block 0 (000800-003fffh) protected from table reads executed in other blocks legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state u-0 r/c-1 u-0 u-0 u-0 u-0 u-0 u-0 ? ebtrb ? ? ? ? ? ? bit 7 bit 0 bit 7 unimplemented: read as ? 0 ? bit 6 ebtrb: boot block table read protection bit 1 = boot block (000000-0007ffh) not protected from table reads executed in other blocks 0 = boot block (000000-0007ffh) protected from table reads executed in other blocks bit 5-0 unimplemented: read as ? 0 ? legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state
? 2004 microchip technology inc. preliminary ds39625b-page 351 pic18f2585/2680/4585/4680 register 24-12: device id register 1 for pic18f2585/2680/4585/4680 devices register 24-13: device id register 2 for pic18f2585/2680/4585/4680 devices rrrrrrrr dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 bit 7 bit 0 bit 7-5 dev2:dev0: device id bits 111 = pic18f2585 110 = pic18f2680 101 = pic18f4585 100 = pic18f4680 bit 4-0 rev4:rev0: revision id bits these bits are used to indicate the device revision. legend: r = read-only bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state rrrrrrrr dev10 dev9 dev8 dev7 dev6 dev5 dev4 dev3 bit 7 bit 0 bit 7-0 dev10:dev3: device id bits these bits are used with the dev2:dev0 bits in the device id register 1 to identify the part number. 0000 1110 = pic18f2585/2680/4585/4680 devices note: these values for dev10:dev3 may be shared with other devices. the specific device is always identified by using the entire dev10:dev0 bit sequence. legend: r = read-only bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state
pic18f2585/2680/4585/4680 ds39625b-page 352 preliminary ? 2004 microchip technology inc. 24.2 watchdog timer (wdt) for pic18f2585/2680/4585/4680 devices, the wdt is driven by the intrc source. when the wdt is enabled, the clock source is also enabled. the nominal wdt period is 4 ms and has the same stability as the intrc oscillator. the 4 ms period of the wdt is multiplied by a 16-bit postscaler. any output of the wdt postscaler is selected by a multiplexer, controlled by bits in configu- ration register 2h. available periods range from 4 ms to 131.072 seconds (2.18 minutes). the wdt and postscaler are cleared when any of the following events occur: a sleep or clrwdt instruction is executed, the ircf bits (osccon<6:4>) are changed or a clock failure has occurred. . 24.2.1 control register register 24-14 shows the wdtcon register. this is a readable and writable register which contains a control bit that allows software to override the wdt enable configuration bit, but only if the configuration bit has disabled the wdt. figure 24-1: wdt block diagram note 1: the clrwdt and sleep instructions clear the wdt and postscaler counts when executed. 2: changing the setting of the ircf bits (osccon<6:4>) clears the wdt and postscaler counts. 3: when a clrwdt instruction is executed, the postscaler count will be cleared. intrc source wdt wake-up reset wdt wdt counter programmable postscaler 1:1 to 1:32,768 enable wdt wdtps<3:0> swdten wdten clrwdt 4 from power reset all device resets sleep intrc control 128 change on ircf bits managed modes
? 2004 microchip technology inc. preliminary ds39625b-page 353 pic18f2585/2680/4585/4680 register 24-14: wdtcon: watchdog timer control register table 24-2: summary of watchdog timer registers u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ?swdten (1) bit 7 bit 0 bit 7-1 unimplemented : read as ? 0 ? bit 0 swdten: software controlled watchdog timer enable bit (1) 1 = watchdog timer is on 0 = watchdog timer is off note 1: this bit has no effect if the configuration bit, wdten, is enabled. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por name bit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0 reset values on page rcon ipen sboren ? ri to pd por bor 48 wdtcon ? ? ? ? ? ? ?swdten50 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the watchdog timer.
pic18f2585/2680/4585/4680 ds39625b-page 354 preliminary ? 2004 microchip technology inc. 24.3 two-speed start-up the two-speed start-up feature helps to minimize the latency period from oscillator start-up to code execution by allowing the microcontroller to use the intrc oscillator as a clock source until the primary clock source is available. it is enabled by setting the ieso configuration bit. two-speed start-up should be enabled only if the primary oscillator mode is lp, xt, hs or hspll (crystal-based modes). other sources do not require an ost start-up delay; for these, two-speed start-up should be disabled. when enabled, resets and wake-ups from sleep mode cause the device to configure itself to run from the internal oscillator block as the clock source, following the time-out of the power-up timer after a power-on reset is enabled. this allows almost immediate code execution while the primary oscillator starts and the ost is running. once the ost times out, the device automatically switches to pri_run mode. because the osccon register is cleared on reset events, the intosc (or postscaler) clock source is not initially available after a reset event; the intrc clock is used directly at its base frequency. to use a higher clock speed on wake-up, the intosc or postscaler clock sources can be selected to provide a higher clock speed by setting bits, ircf2:ircf0, immediately after reset. for wake-ups from sleep, the intosc or postscaler clock sources can be selected by setting the ircf2:ircf0 bits prior to entering sleep mode. in all other power managed modes, two-speed start-up is not used. the device will be clocked by the currently selected clock source until the primary clock source becomes available. the setting of the ieso bit is ignored. 24.3.1 special considerations for using two-speed start-up while using the intrc oscillator in two-speed start-up, the device still obeys the normal command sequences for entering power managed modes, including serial sleep instructions (refer to section 3.1.4 ?multiple sleep commands? ). in practice, this means that user code can change the scs1:scs0 bit settings or issue sleep instructions before the ost times out. this would allow an application to briefly wake-up, perform routine ?housekeeping? tasks and return to sleep before the device starts to operate from the primary oscillator. user code can also check if the primary clock source is currently providing the device clocking by checking the status of the osts bit (osccon<3>). if the bit is set, the primary oscillator is providing the clock. otherwise, the internal oscillator block is providing the clock during wake-up from reset or sleep mode. figure 24-2: timing transition for two-speed start-up (intosc to hspll) q1 q3 q4 osc1 peripheral program pc pc + 2 intosc pll clock q1 pc + 6 q2 output q3 q4 q1 cpu clock pc + 4 clock counter q2 q2 q3 note 1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. wake from interrupt event t pll (1) 12 n-1n clock osts bit set transition multiplexer t ost (1)
? 2004 microchip technology inc. preliminary ds39625b-page 355 pic18f2585/2680/4585/4680 24.4 fail-safe clock monitor the fail-safe clock monitor (fscm) allows the microcontroller to continue operation in the event of an external oscillator failure by automatically switching the device clock to the internal oscillator block. the fscm function is enabled by setting the fcmen configuration bit. when fscm is enabled, the intrc oscillator runs at all times to monitor clocks to peripherals and provide a backup clock in the event of a clock failure. clock monitoring (shown in figure 24-3) is accomplished by creating a sample clock signal, which is the intrc out- put divided by 64. this allows ample time between fscm sample clocks for a peripheral clock edge to occur. the peripheral device clock and the sample clock are presented as inputs to the clock monitor latch (cm). the cm is set on the falling edge of the device clock source, but cleared on the rising edge of the sample clock. figure 24-3: fscm block diagram clock failure is tested for on the falling edge of the sample clock. if a sample clock falling edge occurs while cm is still set, a clock failure has been detected (figure 24-4). this causes the following:  the fscm generates an oscillator fail interrupt by setting bit oscfif (pir2<7>);  the device clock source is switched to the internal oscillator block (osccon is not updated to show the current clock source ? this is the fail-safe condition); and the wdt is reset. during switchover, the postscaler frequency from the internal oscillator block may not be sufficiently stable for timing sensitive applications. in these cases, it may be desirable to select another clock configuration and enter an alternate power managed mode. this can be done to attempt a partial recovery or execute a controlled shut- down. see section 3.1.4 ?multiple sleep commands? and section 24.3.1 ?special considerations for using two-speed start-up? for more details. to use a higher clock speed on wake-up, the intosc or postscaler clock sources can be selected to provide a higher clock speed by setting bits, ircf2:ircf0, immediately after reset. for wake-ups from sleep, the intosc or postscaler clock sources can be selected by setting the ircf2:ircf0 bits prior to entering sleep mode. the fscm will detect failures of the primary or second- ary clock sources only. if the internal oscillator block fails, no failure would be detected, nor would any action be possible. 24.4.1 fscm and the watchdog timer both the fscm and the wdt are clocked by the intrc oscillator. since the wdt operates with a separate divider and counter, disabling the wdt has no effect on the operation of the intrc oscillator when the fscm is enabled. as already noted, the clock source is switched to the intosc clock when a clock failure is detected. depending on the frequency selected by the ircf2:ircf0 bits, this may mean a substantial change in the speed of code execution. if the wdt is enabled with a small prescale value, a decrease in clock speed allows a wdt time-out to occur and a subsequent device reset. for this reason, fail-safe clock events also reset the wdt and postscaler, allowing it to start timing from when execution speed was changed and decreasing the likelihood of an erroneous time-out. 24.4.2 exiting fail-safe operation the fail-safe condition is terminated by either a device reset or by entering a power managed mode. on reset, the controller starts the primary clock source specified in configuration register 1h (with any required start-up delays that are required for the oscillator mode, such as ost or pll timer). the intosc multiplexer provides the device clock until the primary clock source becomes ready (similar to a two- speed start-up). the clock source is then switched to the primary clock (indicated by the osts bit in the osccon register becoming set). the fail-safe clock monitor then resumes monitoring the peripheral clock. the primary clock source may never become ready during start-up. in this case, operation is clocked by the intosc multiplexer. the osccon register will remain in its reset state until a power managed mode is entered. peripheral intrc 64 s c q (32 s) 488 hz (2.048 ms) clock monitor latch (cm) (edge-triggered) clock failure detected source clock q
pic18f2585/2680/4585/4680 ds39625b-page 356 preliminary ? 2004 microchip technology inc. figure 24-4: fscm timing diagram 24.4.3 fscm interrupts in power managed modes by entering a power managed mode, the clock multiplexer selects the clock source selected by the osccon register. fail-safe monitoring of the power managed clock source resumes in the power managed mode. if an oscillator failure occurs during power managed operation, the subsequent events depend on whether or not the oscillator failure interrupt is enabled. if enabled (oscfif = 1 ), code execution will be clocked by the intosc multiplexer. an automatic transition back to the failed clock source will not occur. if the interrupt is disabled, subsequent interrupts while in idle mode will cause the cpu to begin executing instructions while being clocked by the intosc source. 24.4.4 por or wake-up from sleep the fscm is designed to detect oscillator failure at any point after the device has exited power-on reset (por) or low-power sleep mode. when the primary device clock is ec, rc or intrc modes, monitoring can begin immediately following these events. for oscillator modes involving a crystal or resonator (hs, hspll, lp or xt), the situation is somewhat different. since the oscillator may require a start-up time considerably longer than the fcsm sample clock time, a false clock failure may be detected. to prevent this, the internal oscillator block is automatically config- ured as the device clock and functions until the primary clock is stable (the ost and pll timers have timed out). this is identical to two-speed start-up mode. once the primary clock is stable, the intrc returns to its role as the fscm source. as noted in section 24.3.1 ?special considerations for using two-speed start-up? , it is also possible to select another clock configuration and enter an alternate power managed mode while waiting for the primary clock to become stable. when the new power managed mode is selected, the primary clock is disabled. oscfif cm output device clock output sample clock failure detected oscillator failure note: the device clock is normally at a mu ch higher frequency than the sample clock. the relative frequencies in this example have been chosen for clarity. (q ) cm test cm test cm test note: the same logic that prevents false oscilla- tor failure interrupts on por, or wake from sleep, will also prevent the detection of the oscillator?s failure to start at all follow- ing these events. this can be avoided by monitoring the osts bit and using a timing routine to determine if the oscillator is taking too long to start. even so, no oscillator failure interrupt will be flagged.
? 2004 microchip technology inc. preliminary ds39625b-page 357 pic18f2585/2680/4585/4680 24.5 program verification and code protection the overall structure of the code protection on the pic18 flash devices differs significantly from other picmicro ? devices. the user program memory is divided into five blocks. one of these is a boot block of 2 kbytes. the remainder of the memory is divided into four blocks on binary boundaries. each of the five blocks has three code protection bits associated with them. they are:  code-protect bit (cpn)  write-protect bit (wrtn)  external block table read bit (ebtrn) figure 24-5 shows the program memory organization for 48 and 64-kbyte devices and the specific code protection bit associated with each block. the actual locations of the bits are summarized in table 24-3. figure 24-5: code-protected program memory for pic18f2585/2680/4585/4680 table 24-3: summary of code protection registers file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 300008h config5l ? ? ? ? cp3* cp2 cp1 cp0 300009h config5h cpd cpb ? ? ? ? ? ? 30000ah config6l ? ? ? ? wrt3* wrt2 wrt1 wrt0 30000bh config6h wrtd wrtb wrtc ? ? ? ? ? 30000ch config7l ? ? ? ? ebtr3* ebtr2 ebtr1 ebtr0 30000dh config7h ? ebtrb ? ? ? ? ? ? legend: shaded cells are unimplemented. * unimplemented in pic18fx585 devices; maintain this bit set. memory size/device block code protection controlled by: 48 kbytes (pic18f2585/4585) 64 kbytes (pic18f2680/4680) address range boot block boot block 000000h 0007ffh cpb, wrtb, ebtrb block 0 block 0 000800h 003fffh cp0, wrt0, ebtr0 block 1 block 1 004000h 007fffh cp1, wrt1, ebtr1 block 2 block 2 008000h 00b7ffh cp2, wrt2, ebtr2 unimplemented read ? 0 ?s block 3 00c000h 00ffffh cp3, wrt3, ebtr3 unimplemented read ? 0 ?s unimplemented read ? 0 ?s 010000h 1fffffh (unimplemented memory space)
pic18f2585/2680/4585/4680 ds39625b-page 358 preliminary ? 2004 microchip technology inc. 24.5.1 program memory code protection the program memory may be read to or written from any location using the table read and table write instructions. the device id may be read with table reads. the configuration registers may be read and written with the table read and table write instructions. in normal execution mode, the cpn bits have no direct effect. cpn bits inhibit external reads and writes. a block of user memory may be protected from table writes if the wrtn configuration bit is ? 0 ?. the ebtrn bits control table reads. for a block of user memory with the ebtrn bit set to ? 0 ?, a table read instruction that executes from within that block is allowed to read. a table read instruction that executes from a location outside of that block is not allowed to read and will result in reading ? 0 ?s. figures 24-6 through 24-8 illustrate table write and table read protection. figure 24-6: table write (wrtn) disallowed note: code protection bits may only be written to a ? 0 ? from a ? 1 ? state. it is not possible to write a ? 1 ? to a bit in the ? 0 ? state. code protection bits are only set to ? 1 ? by a full chip erase or block erase function. the full chip erase and block erase functions can only be initiated via icsp or an external programmer. 000000h 0007ffh 000800h 003fffh 004000h 007fffh 008000h 00bfffh 00c000h 00ffffh wrtb, ebtrb = 11 wrt0, ebtr0 = 01 wrt1, ebtr1 = 11 wrt2, ebtr2 = 11 wrt3, ebtr3 = 11 tblwt* tblptr = 0008ffh pc = 003ffeh tblwt* pc = 00bffeh register values program memory configuration bit settings results: all table writes disabled to blockn whenever wrtn = 0 .
? 2004 microchip technology inc. preliminary ds39625b-page 359 pic18f2585/2680/4585/4680 figure 24-7: external block t able read (ebtrn) disallowed figure 24-8: external block table read (ebtrn) allowed wrtb, ebtrb = 11 wrt0, ebtr0 = 10 wrt1, ebtr1 = 11 wrt2, ebtr2 = 11 wrt3, ebtr3 = 11 tblrd* tblptr = 0008ffh pc = 007ffeh results: all table reads from external blocks to blockn are disabled whenever ebtrn = 0 . tablat register returns a value of ? 0 ?. register values program memory configuration bit settings 000000h 0007ffh 000800h 003fffh 004000h 007fffh 008000h 00bfffh 00c000h 00ffffh wrtb, ebtrb = 11 wrt0, ebtr0 = 10 wrt1, ebtr1 = 11 wrt2, ebtr2 = 11 wrt3, ebtr3 = 11 tblrd* tblptr = 0008ffh pc = 003ffeh register values program memory configuration bit settings results: table reads permitted within blockn, even when ebtrbn = 0 . tablat register returns the value of the data at the location tblptr. 000000h 0007ffh 000800h 003fffh 004000h 007fffh 008000h 00bfffh 00c000h 00ffffh
pic18f2585/2680/4585/4680 ds39625b-page 360 preliminary ? 2004 microchip technology inc. 24.5.2 data eeprom code protection the entire data eeprom is protected from external reads and writes by two bits: cpd and wrtd. cpd inhibits external reads and writes of data eeprom. wrtd inhibits internal and external writes to data eeprom. the cpu can continue to read and write data eeprom regardless of the protection bit settings. 24.5.3 configuration register protection the configuration registers can be write-protected. the wrtc bit controls protection of the configuration registers. in normal execution mode, the wrtc bit is readable only. wrtc can only be written via icsp or an external programmer. 24.6 id locations eight memory locations (200000h-200007h) are designated as id locations, where the user can store checksum or other code identification numbers. these locations are both readable and writable during normal execution through the tblrd and tblwt instructions or during program/verify. the id locations can be read when the device is code-protected. 24.7 in-circuit serial programming pic18f2585/2680/4585/4680 microcontrollers can be serially programmed while in the end application circuit. this is simply done with two lines for clock and data and three other lines for power, ground and the programming voltage. this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed. 24.8 in-circuit debugger when the debug configuration bit is programmed to a ? 0 ?, the in-circuit debugger functionality is enabled. this function allows simple debugging functions when used with mplab ? ide. when the microcontroller has this feature enabled, some resources are not available for general use. table 24-4 shows which resources are required by the background debugger. table 24-4: debugger resources to use the in-circuit debugger function of the micro- controller, the design must implement in-circuit serial programming connections to mclr /v pp /re3, v dd , v ss , rb7 and rb6. this will interface to the in-circuit debugger module available from microchip or one of the third party development tool companies. 24.9 single-supply icsp programming the lvp configuration bit enables single-supply icsp programming (formerly known as low-voltage icsp programming or lvp ). when single-supply program- ming is enabled, the microcontroller can be programmed without requiring high voltage being applied to the mclr /v pp /re3 pin, but the rb5/kbi1/pgm pin is then dedicated to controlling program mode entry and is not available as a general purpose i/o pin. while programming using single-supply programming, v dd is applied to the mclr /v pp /re3 pin as in normal execution mode. to enter programming mode, v dd is applied to the pgm pin. if single-supply icsp programming mode will not be used, the lvp bit can be cleared. rb5/kbi1/pgm then becomes available as the digital i/o pin, rb5. the lvp bit may be set or cleared only when using standard high-voltage programming (v ihh applied to the mclr / v pp /re3 pin). once lvp has been disabled, only the standard high-voltage programming is available and must be used to program the device. memory that is not code-protected can be erased using either a block erase, or erased row by row, then written at any specified v dd . if code-protected memory is to be erased, a block erase is required. if a block erase is to be performed when using low-voltage programming, the device must be supplied with v dd of 4.5v to 5.5v. i/o pins: rb6, rb7 stack: 2 levels program memory: 512 bytes data memory: 10 bytes note 1: high-voltage programming is always avail- able, regardless of the state of the lvp bit, by applying v ihh to the mclr pin. 2: while in low-voltage icsp programming mode, the rb5 pin can no longer be used as a general purpose i/o pin and should be held low during normal operation. 3: when using low-voltage icsp program- ming (lvp) and the pull-ups on portb are enabled, bit 5 in the trisb register must be cleared to disable the pull-up on rb5 and ensure the proper operation of the device. 4: if the device master clear is disabled, verify that either of the following is done to ensure proper entry into icsp mode: a) disable low-voltage programming (config4l<2> = 0 ); or b) make certain that rb5/pgm is held low during entry into icsp.
? 2004 microchip technology inc. preliminary ds39625b-page 361 pic18f2585/2680/4585/4680 25.0 instruction set summary pic18f2585/2680/4585/4680 devices incorporate the standard set of 75 pic18 core instructions, as well as an extended set of 8 new instructions, for the optimiza- tion of code that is recursive or that utilizes a software stack. the extended set is discussed later in this section. 25.1 standard instruction set the standard pic18 instruction set adds many enhancements to the previous picmicro ? instruction sets, while maintaining an easy migration from these picmicro instruction sets. most instructions are a single program memory word (16 bits), but there are four instructions that require two program memory locations. each single-word instruction is a 16-bit word divided into an opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the instruction set is highly orthogonal and is grouped into four basic categories:  byte-oriented operations  bit-oriented operations  literal operations  control operations the pic18 instruction set summary in table 25-2 lists byte-oriented , bit-oriented , literal and control operations. table 25-1 shows the opcode field descriptions. most byte-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the destination of the result (specified by ?d?) 3. the accessed memory (specified by ?a?) the file register designator ?f? specifies which file register is to be used by the instruction. the destination designator ?d? specifies where the result of the opera- tion is to be placed. if ?d? is zero, the result is placed in the wreg register. if ?d? is one, the result is placed in the file register specified in the instruction. all bit-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the bit in the file register (specified by ?b?) 3. the accessed memory (specified by ?a?) the bit field designator ?b? selects the number of the bit affected by the operation, while the file register designator ?f? represents the number of the file in which the bit is located. the literal instructions may use some of the following operands:  a literal value to be loaded into a file register (specified by ?k?)  the desired fsr register to load the literal value into (specified by ?f?)  no operand required (specified by ???) the control instructions may use some of the following operands:  a program memory address (specified by ?n?)  the mode of the call or return instructions (specified by ?s?)  the mode of the table read and table write instructions (specified by ?m?)  no operand required (specified by ???) all instructions are a single word, except for four double-word instructions. these instructions were made double-word to contain the required information in 32 bits. in the second word, the 4 msbs are ? 1 ?s. if this second word is executed as an instruction (by itself), it will execute as a nop . all single-word instructions are executed in a single instruction cycle, unless a conditional test is true or the program counter is changed as a result of the instruc- tion. in these cases, the execution takes two instruction cycles with the additional instruction cycle(s) executed as a nop . the double-word instructions execute in two instruction cycles. one instruction cycle consists of four oscillator periods. thus, for an oscillator frequency of 4 mhz, the normal instruction execution time is 1 s. if a conditional test is true, or the program counter is changed as a result of an instruction, the instruction execution time is 2 s. two-word branch instructions (if true) would take 3 s. figure 25-1 shows the general formats that the instruc- tions can have. all examples use the convention ?nnh? to represent a hexadecimal number. the instruction set summary, shown in table 25-2, lists the standard instructions recognized by the microchip mpasm? assembler. section 25.1.1 ?standard instruction set? provides a description of each instruction.
pic18f2585/2680/4585/4680 ds39625b-page 362 preliminary ? 2004 microchip technology inc. table 25-1: opcode field descriptions field description a ram access bit a = 0 : ram location in access ram (bsr register is ignored) a = 1 : ram bank is specified by bsr register bbb bit address within an 8-bit file register (0 to 7). bsr bank select register. used to select the current ram bank. c, dc, z, ov, n alu status bits: c arry, d igit c arry, z ero, ov erflow, n egative. d destination select bit d = 0 : store result in wreg d = 1 : store result in file register f dest destination: either the wreg register or the specified register file location. f 8-bit register file address (00h to ffh), or 2-bit fsr designator (0h to 3h). f s 12-bit register file address (000h to ff fh). this is the source address. f d 12-bit register file address (000h to fffh). this is the destination address. gie global interrupt enable bit. k literal field, constant data or label (may be either an 8-bit, 12-bit or a 20-bit value) label label name mm the mode of the tblptr register for the table read and table write instructions. only used with table read and table write instructions: * no change to register (such as tblptr with table reads and writes) *+ post-increment register (such as tblptr with table reads and writes) *- post-decrement register (such as tblptr with table reads and writes) +* pre-increment register (such as tb lptr with table reads and writes) n the relative address (2?s complement number) for relative branch instructions or the direct address for call/branch and return instructions pc program counter. pcl program counter low byte. pch program counter high byte. pclath program counter high byte latch. pclatu program counter upper byte latch. pd power-down bit. prodh product of multiply high byte. prodl product of multiply low byte. s fast call/return mode select bit s = 0 : do not update into/from shadow registers s = 1 : certain registers loaded into/from shadow registers (fast mode) tblptr 21-bit table pointer (points to a program memory location). tablat 8-bit table latch. to time-out bit. tos top-of-stack. u unused or unchanged. wdt watchdog timer. wreg working register (accumulator). x don?t care (? 0 ? or ? 1 ?). the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. z s 7-bit offset value for indirect addr essing of register files (source). z d 7-bit offset value for indirect addressing of register files (destination). { } optional argument. [text] indicates an indexed address. (text) the contents of text . [expr] specifies bit n of the register indicated by the pointer expr . assigned to. < > register bit field. in the set of. italics user defined term (font is courier).
? 2004 microchip technology inc. preliminary ds39625b-page 363 pic18f2585/2680/4585/4680 figure 25-1: general format for instructions byte-oriented file register operations 15 10 9 8 7 0 d = 0 for result destination to be wreg register opcode d a f (file #) d = 1 for result destination to be file register (f) a = 0 to force access bank bit-oriented file register operations 15 12 11 9 8 7 0 opcode b (bit #) a f (file #) b = 3-bit position of bit in file register (f) literal operations 15 8 7 0 opcode k (literal) k = 8-bit immediate value byte to byte move operations (2-word) 15 12 11 0 opcode f (source file #) call, goto and branch operations 15 8 7 0 opcode n<7:0> (literal) n = 20-bit immediate value a = 1 for bsr to select bank f = 8-bit file register address a = 0 to force access bank a = 1 for bsr to select bank f = 8-bit file register address 15 12 11 0 1111 n<19:8> (literal) 15 12 11 0 1111 f (destination file #) f = 12-bit file register address control operations example instruction addwf myreg, w, b movff myreg1, myreg2 bsf myreg, bit, b movlw 7fh goto label 15 8 7 0 opcode n<7:0> (literal) 15 12 11 0 1111 n<19:8> (literal) call myfunc 15 11 10 0 opcode n<10:0> (literal) s = fast bit bra myfunc 15 8 7 0 opcode n<7:0> (literal) bc myfunc s
pic18f2585/2680/4585/4680 ds39625b-page 364 preliminary ? 2004 microchip technology inc. table 25-2: pic18fxxxx instruction set mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb byte-oriented operations addwf addwfc andwf clrf comf cpfseq cpfsgt cpfslt decf decfsz dcfsnz incf incfsz infsnz iorwf movf movff movwf mulwf negf rlcf rlncf rrcf rrncf setf subfwb subwf subwfb swapf tstfsz xorwf f, d, a f, d, a f, d, a f, a f, d, a f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f s , f d f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a add wreg and f add wreg and carry bit to f and wreg with f clear f complement f compare f with wreg, skip = compare f with wreg, skip > compare f with wreg, skip < decrement f decrement f, skip if 0 decrement f, skip if not 0 increment f increment f, skip if 0 increment f, skip if not 0 inclusive or wreg with f move f move f s (source) to 1st word f d (destination)2nd word move wreg to f multiply wreg with f negate f rotate left f through carry rotate left f (no carry) rotate right f through carry rotate right f (no carry) set f subtract f from wreg with borrow subtract wreg from f subtract wreg from f with borrow swap nibbles in f test f, skip if 0 exclusive or wreg with f 1 1 1 1 1 1 (2 or 3) 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 (2 or 3) 1 0010 0010 0001 0110 0001 0110 0110 0110 0000 0010 0100 0010 0011 0100 0001 0101 1100 1111 0110 0000 0110 0011 0100 0011 0100 0110 0101 0101 0101 0011 0110 0001 01da 00da 01da 101a 11da 001a 010a 000a 01da 11da 11da 10da 11da 10da 00da 00da ffff ffff 111a 001a 110a 01da 01da 00da 00da 100a 01da 11da 10da 10da 011a 10da ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff c, dc, z, ov, n c, dc, z, ov, n z, n z z, n none none none c, dc, z, ov, n none none c, dc, z, ov, n none none z, n z, n none none none c, dc, z, ov, n c, z, n z, n c, z, n z, n none c, dc, z, ov, n c, dc, z, ov, n c, dc, z, ov, n none none z, n 1, 2 1, 2 1,2 2 1, 2 4 4 1, 2 1, 2, 3, 4 1, 2, 3, 4 1, 2 1, 2, 3, 4 4 1, 2 1, 2 1 1, 2 1, 2 1, 2 1, 2 4 1, 2 note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and where applicable, ?d? = 1 ), the prescaler will be cleared if assigned. 3: if program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction. 5: if the table write starts the write cycle to internal memory, the write will continue until terminated.
? 2004 microchip technology inc. preliminary ds39625b-page 365 pic18f2585/2680/4585/4680 bit-oriented operations bcf bsf btfsc btfss btg f, b, a f, b, a f, b, a f, b, a f, d, a bit clear f bit set f bit test f, skip if clear bit test f, skip if set bit toggle f 1 1 1 (2 or 3) 1 (2 or 3) 1 1001 1000 1011 1010 0111 bbba bbba bbba bbba bbba ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff none none none none none 1, 2 1, 2 3, 4 3, 4 1, 2 control operations bc bn bnc bnn bnov bnz bov bra bz call clrwdt daw goto nop nop pop push rcall reset retfie retlw return sleep n n n n n n n n n n, s ? ? n ? ? ? ? n s k s ? branch if carry branch if negative branch if not carry branch if not negative branch if not overflow branch if not zero branch if overflow branch unconditionally branch if zero call subroutine1st word 2nd word clear watchdog timer decimal adjust wreg go to address 1st word 2nd word no operation no operation pop top of return stack (tos) push top of return stack (tos) relative call software device reset return from interrupt enable return with literal in wreg return from subroutine go into standby mode 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 2 1 (2) 2 1 1 2 1 1 1 1 2 1 2 2 2 1 1110 1110 1110 1110 1110 1110 1110 1101 1110 1110 1111 0000 0000 1110 1111 0000 1111 0000 0000 1101 0000 0000 0000 0000 0000 0010 0110 0011 0111 0101 0001 0100 0nnn 0000 110s kkkk 0000 0000 1111 kkkk 0000 xxxx 0000 0000 1nnn 0000 0000 1100 0000 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0000 0000 kkkk kkkk 0000 xxxx 0000 0000 nnnn 1111 0001 kkkk 0001 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0100 0111 kkkk kkkk 0000 xxxx 0110 0101 nnnn 1111 000s kkkk 001s 0011 none none none none none none none none none none to , pd c none none none none none none all gie/gieh, peie/giel none none to , pd 4 table 25-2: pic18fxxxx instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and where applicable, ?d? = 1 ), the prescaler will be cleared if assigned. 3: if program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction. 5: if the table write starts the write cycle to internal memory, the write will continue until terminated.
pic18f2585/2680/4585/4680 ds39625b-page 366 preliminary ? 2004 microchip technology inc. literal operations addlw andlw iorlw lfsr movlb movlw mullw retlw sublw xorlw k k k f, k k k k k k k add literal and wreg and literal with wreg inclusive or literal with wreg move literal (12-bit) 2nd word to fsr(f) 1st word move literal to bsr<3:0> move literal to wreg multiply literal with wreg return with literal in wreg subtract wreg from literal exclusive or literal with wreg 1 1 1 2 1 1 1 2 1 1 0000 0000 0000 1110 1111 0000 0000 0000 0000 0000 0000 1111 1011 1001 1110 0000 0001 1110 1101 1100 1000 1010 kkkk kkkk kkkk 00ff kkkk 0000 kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk c, dc, z, ov, n z, n z, n none none none none none c, dc, z, ov, n z, n data memory ? program memory operations tblrd* tblrd*+ tblrd*- tblrd+* tblwt* tblwt*+ tblwt*- tblwt+* table read table read with post-increment table read with post-decrement table read with pre-increment table write table write with post-increment table write with post-decrement table write with pre-increment 2 2 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1000 1001 1010 1011 1100 1101 1110 1111 none none none none none none none none 5 5 5 5 table 25-2: pic18fxxxx instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and where applicable, ?d? = 1 ), the prescaler will be cleared if assigned. 3: if program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction. 5: if the table write starts the write cycle to internal memory, the write will continue until terminated.
? 2004 microchip technology inc. preliminary ds39625b-page 367 pic18f2585/2680/4585/4680 25.1.1 standard instruction set addlw add literal to w syntax: addlw k operands: 0 k 255 operation: (w) + k w status affected: n, ov, c, dc, z encoding: 0000 1111 kkkk kkkk description: the contents of w are added to the 8-bit literal ?k? and the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: addlw 15h before instruction w = 10h after instruction w = 25h addwf add w to f syntax: addwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) + (f) dest status affected: n, ov, c, dc, z encoding: 0010 01da ffff ffff description: add w to register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: addwf reg, 0, 0 before instruction w = 17h reg = 0c2h after instruction w = 0d9h reg = 0c2h note: all pic18 instructions may take an optional label ar gument preceding the instruction mnemonic for use in symbolic addressing. if a label is used, the instruct ion format then becomes: {label} instruction argument(s).
pic18f2585/2680/4585/4680 ds39625b-page 368 preliminary ? 2004 microchip technology inc. addwfc add w and carry bit to f syntax: addwfc f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) + (f) + (c) dest status affected: n,ov, c, dc, z encoding: 0010 00da ffff ffff description: add w, the carry flag and data memory location ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in data memory location ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: addwfc reg, 0, 1 before instruction carry bit = 1 reg = 02h w=4dh after instruction carry bit = 0 reg = 02h w = 50h andlw and literal with w syntax: andlw k operands: 0 k 255 operation: (w) .and. k w status affected: n, z encoding: 0000 1011 kkkk kkkk description: the contents of w are anded with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: andlw 05fh before instruction w=a3h after instruction w = 03h
? 2004 microchip technology inc. preliminary ds39625b-page 369 pic18f2585/2680/4585/4680 andwf and w with f syntax: andwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) .and. (f) dest status affected: n, z encoding: 0001 01da ffff ffff description: the contents of w are and?ed with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: andwf reg, 0, 0 before instruction w = 17h reg = c2h after instruction w = 02h reg = c2h bc branch if carry syntax: bc n operands: -128 n 127 operation: if carry bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0010 nnnn nnnn description: if the carry bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bc 5 before instruction pc = address (here) after instruction if carry = 1; pc = address (here + 12) if carry = 0; pc = address (here + 2)
pic18f2585/2680/4585/4680 ds39625b-page 370 preliminary ? 2004 microchip technology inc. bcf bit clear f syntax: bcf f, b {,a} operands: 0 f 255 0 b 7 a [0,1] operation: 0 f status affected: none encoding: 1001 bbba ffff ffff description: bit ?b? in register ?f? is cleared. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: bcf flag_reg, 7, 0 before instruction flag_reg = c7h after instruction flag_reg = 47h bn branch if negative syntax: bn n operands: -128 n 127 operation: if negative bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0110 nnnn nnnn description: if the negative bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bn jump before instruction pc = address (here) after instruction if negative = 1; pc = address (jump) if negative = 0; pc = address (here + 2)
? 2004 microchip technology inc. preliminary ds39625b-page 371 pic18f2585/2680/4585/4680 bnc branch if not carry syntax: bnc n operands: -128 n 127 operation: if carry bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0011 nnnn nnnn description: if the carry bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnc jump before instruction pc = address (here) after instruction if carry = 0; pc = address (jump) if carry = 1; pc = address (here + 2) bnn branch if not negative syntax: bnn n operands: -128 n 127 operation: if negative bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0111 nnnn nnnn description: if the negative bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnn jump before instruction pc = address (here) after instruction if negative = 0; pc = address (jump) if negative = 1; pc = address (here + 2)
pic18f2585/2680/4585/4680 ds39625b-page 372 preliminary ? 2004 microchip technology inc. bnov branch if not overflow syntax: bnov n operands: -128 n 127 operation: if overflow bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0101 nnnn nnnn description: if the overflow bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnov jump before instruction pc = address (here) after instruction if overflow = 0; pc = address (jump) if overflow = 1; pc = address (here + 2) bnz branch if not zero syntax: bnz n operands: -128 n 127 operation: if zero bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0001 nnnn nnnn description: if the zero bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnz jump before instruction pc = address (here) after instruction if zero = 0; pc = address (jump) if zero = 1; pc = address (here + 2)
? 2004 microchip technology inc. preliminary ds39625b-page 373 pic18f2585/2680/4585/4680 bra unconditional branch syntax: bra n operands: -1024 n 1023 operation: (pc) + 2 + 2n pc status affected: none encoding: 1101 0nnn nnnn nnnn description: add the 2?s complement number ?2n? to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation example: here bra jump before instruction pc = address (here) after instruction pc = address (jump) bsf bit set f syntax: bsf f, b {,a} operands: 0 f 255 0 b 7 a [0,1] operation: 1 f status affected: none encoding: 1000 bbba ffff ffff description: bit ?b? in register ?f? is set. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: bsf flag_reg, 7, 1 before instruction flag_reg = 0ah after instruction flag_reg = 8ah
pic18f2585/2680/4585/4680 ds39625b-page 374 preliminary ? 2004 microchip technology inc. btfsc bit test file, skip if clear syntax: btfsc f, b {,a} operands: 0 f 255 0 b 7 a [0,1] operation: skip if (f) = 0 status affected: none encoding: 1011 bbba ffff ffff description: if bit ?b? in register ?f? is ? 0 ?, then the next instruction is skipped. if bit ?b? is ? 0 ?, then the next instruction fetched during the current instruction execution is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here false true btfsc : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0; pc = address (true) if flag<1> = 1; pc = address (false) btfss bit test file, skip if set syntax: btfss f, b {,a} operands: 0 f 255 0 b < 7 a [0,1] operation: skip if (f) = 1 status affected: none encoding: 1010 bbba ffff ffff description: if bit ?b? in register ?f? is ? 1 ?, then the next instruction is skipped. if bit ?b? is ? 1 ?, then the next instruction fetched during the current instruction execution is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here false true btfss : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0; pc = address (false) if flag<1> = 1; pc = address (true)
? 2004 microchip technology inc. preliminary ds39625b-page 375 pic18f2585/2680/4585/4680 btg bit toggle f syntax: btg f, b {,a} operands: 0 f 255 0 b < 7 a [0,1] operation: (f ) f status affected: none encoding: 0111 bbba ffff ffff description: bit ?b? in data memory location ?f? is inverted. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: btg portc, 4, 0 before instruction: portc = 0111 0101 [75h] after instruction: portc = 0110 0101 [65h] bov branch if overflow syntax: bov n operands: -128 n 127 operation: if overflow bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0100 nnnn nnnn description: if the overflow bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bov jump before instruction pc = address (here) after instruction if overflow = 1; pc = address (jump) if overflow = 0; pc = address (here + 2)
pic18f2585/2680/4585/4680 ds39625b-page 376 preliminary ? 2004 microchip technology inc. bz branch if zero syntax: bz n operands: -128 n 127 operation: if zero bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0000 nnnn nnnn description: if the zero bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bz jump before instruction pc = address (here) after instruction if zero = 1; pc = address (jump) if zero = 0; pc = address (here + 2) call subroutine call syntax: call k {,s} operands: 0 k 1048575 s [0,1] operation: (pc) + 4 tos, k pc<20:1>, if s = 1 (w) ws, (status) statuss, (bsr) bsrs status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 110s k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: subroutine call of entire 2-mbyte memory range. first, return address (pc + 4) is pushed onto the return stack. if ?s? = 1 , the w, status and bsr registers are also pushed into their respective shadow registers, ws, statuss and bsrs. if ?s? = 0 , no update occurs (default). then, the 20-bit value ?k? is loaded into pc<20:1>. call is a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, push pc to stack read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example: here call there, 1 before instruction pc = address (here) after instruction pc = address (there) tos = address (here + 4) ws = w bsrs = bsr statuss= status
? 2004 microchip technology inc. preliminary ds39625b-page 377 pic18f2585/2680/4585/4680 clrf clear f syntax: clrf f {,a} operands: 0 f 255 a [0,1] operation: 000h f 1 z status affected: z encoding: 0110 101a ffff ffff description: clears the contents of the specified register. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: clrf flag_reg,1 before instruction flag_reg = 5ah after instruction flag_reg = 00h clrwdt clear watchdog timer syntax: clrwdt operands: none operation: 000h wdt, 000h wdt postscaler, 1 to, 1 pd status affected: to , pd encoding: 0000 0000 0000 0100 description: clrwdt instruction resets the watchdog timer. it also resets the postscaler of the wdt. status bits to and pd are set. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data no operation example: clrwdt before instruction wdt counter = ? after instruction wdt counter = 00h wdt postscaler = 0 to =1 pd =1
pic18f2585/2680/4585/4680 ds39625b-page 378 preliminary ? 2004 microchip technology inc. comf complement f syntax: comf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: dest status affected: n, z encoding: 0001 11da ffff ffff description: the contents of register ?f? are complemented. if ?d? is ? 1 ?, the result is stored in w. if ?d? is ? 0 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: comf reg, 0, 0 before instruction reg = 13h after instruction reg = 13h w=ech (f ) cpfseq compare f with w, skip if f = w syntax: cpfseq f {,a} operands: 0 f 255 a [0,1] operation: (f) ? (w), skip if (f) = (w) (unsigned comparison) status affected: none encoding: 0110 001a ffff ffff description: compares the contents of data memory location ?f? to the contents of w by performing an unsigned subtraction. if ?f? = w, then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 0 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfseq reg, 0 nequal : equal : before instruction pc address = here w=? reg = ? after instruction if reg = w; pc = address (equal) if reg w; pc = address (nequal)
? 2004 microchip technology inc. preliminary ds39625b-page 379 pic18f2585/2680/4585/4680 cpfsgt compare f with w, skip if f > w syntax: cpfsgt f {,a} operands: 0 f 255 a [0,1] operation: (f) ? ( w), skip if (f) > (w) (unsigned comparison) status affected: none encoding: 0110 010a ffff ffff description: compares the contents of data memory location ?f? to the contents of the w by performing an unsigned subtraction. if the contents of ?f? are greater than the contents of wreg , then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfsgt reg, 0 ngreater : greater : before instruction pc = address (here) w= ? after instruction if reg > w; pc = address (greater) if reg w; pc = address (ngreater) cpfslt compare f with w, skip if f < w syntax: cpfslt f {,a} operands: 0 f 255 a [0,1] operation: (f) ? ( w), skip if (f) < (w) (unsigned comparison) status affected: none encoding: 0110 000a ffff ffff description: compares the contents of data memory location ?f? to the contents of w by performing an unsigned subtraction. if the contents of ?f? are less than the contents of w, then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfslt reg, 1 nless : less : before instruction pc = address (here) w= ? after instruction if reg < w; pc = address (less) if reg w; pc = address (nless)
pic18f2585/2680/4585/4680 ds39625b-page 380 preliminary ? 2004 microchip technology inc. daw decimal adjust w register syntax: daw operands: none operation: if [w<3:0> >9] or [dc = 1 ] then (w<3:0>) + 6 w<3:0>; else ( w<3:0>) w<3:0>; if [w<7:4> >9] or [c = 1 ] then ( w<7:4>) + 6 w<7:4>; c = 1 ; else (w<7:4>) w<7:4>; status affected: c encoding: 0000 0000 0000 0111 description: daw adjusts the eight-bit value in w, resulting from the earlier addition of two variables (each in packed bcd format) and produces a correct packed bcd result. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register w process data write w example 1: daw before instruction w=a5h c=0 dc = 0 after instruction w = 05h c=1 dc = 0 example 2 : before instruction w=ceh c=0 dc = 0 after instruction w = 34h c=1 dc = 0 decf decrement f syntax: decf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest status affected: c, dc, n, ov, z encoding: 0000 01da ffff ffff description: decrement register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: decf cnt, 1, 0 before instruction cnt = 01h z=0 after instruction cnt = 00h z=1
? 2004 microchip technology inc. preliminary ds39625b-page 381 pic18f2585/2680/4585/4680 decfsz decrement f, skip if 0 syntax: decfsz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest, skip if result = 0 status affected: none encoding: 0010 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here decfsz cnt, 1, 1 goto loop continue before instruction pc = address (here) after instruction cnt = cnt ? 1 if cnt = 0; pc = address (continue) if cnt 0; pc = address (here + 2) dcfsnz decrement f, skip if not 0 syntax: dcfsnz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest, skip if result 0 status affected: none encoding: 0100 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is not ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here dcfsnz temp, 1, 0 zero : nzero : before instruction temp = ? after instruction temp = temp ? 1, if temp = 0; pc = address (zero) if temp 0; pc = address (nzero)
pic18f2585/2680/4585/4680 ds39625b-page 382 preliminary ? 2004 microchip technology inc. goto unconditional branch syntax: goto k operands: 0 k 1048575 operation: k pc<20:1> status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 1111 k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: goto allows an unconditional branch anywhere within entire 2-mbyte memory range. the 20-bit value ?k? is loaded into pc<20:1>. goto is always a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, no operation read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example: goto there after instruction pc = address (there) incf increment f syntax: incf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest status affected: c, dc, n, ov, z encoding: 0010 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: incf cnt, 1, 0 before instruction cnt = ffh z=0 c=? dc = ? after instruction cnt = 00h z=1 c=1 dc = 1
? 2004 microchip technology inc. preliminary ds39625b-page 383 pic18f2585/2680/4585/4680 incfsz increment f, skip if 0 syntax: incfsz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest, skip if result = 0 status affected: none encoding: 0011 11da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here incfsz cnt, 1, 0 nzero : zero : before instruction pc = address (here) after instruction cnt = cnt + 1 if cnt = 0; pc = address (zero) if cnt 0; pc = address (nzero) infsnz increment f, skip if not 0 syntax: infsnz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest, skip if result 0 status affected: none encoding: 0100 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is not ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here infsnz reg, 1, 0 zero nzero before instruction pc = address (here) after instruction reg = reg + 1 if reg 0; pc = address (nzero) if reg = 0; pc = address (zero)
pic18f2585/2680/4585/4680 ds39625b-page 384 preliminary ? 2004 microchip technology inc. iorlw inclusive or literal with w syntax: iorlw k operands: 0 k 255 operation: (w) .or. k w status affected: n, z encoding: 0000 1001 kkkk kkkk description: the contents of w are ored with the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: iorlw 35h before instruction w=9ah after instruction w=bfh iorwf inclusive or w with f syntax: iorwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) .or. (f) dest status affected: n, z encoding: 0001 00da ffff ffff description: inclusive or w with register ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: iorwf result, 0, 1 before instruction result = 13h w = 91h after instruction result = 13h w = 93h
? 2004 microchip technology inc. preliminary ds39625b-page 385 pic18f2585/2680/4585/4680 lfsr load fsr syntax: lfsr f, k operands: 0 f 2 0 k 4095 operation: k fsrf status affected: none encoding: 1110 1111 1110 0000 00ff k 7 kkk k 11 kkk kkkk description: the 12-bit literal ?k? is loaded into the file select register pointed to by ?f?. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? msb process data write literal ?k? msb to fsrfh decode read literal ?k? lsb process data write literal ?k? to fsrfl example: lfsr 2, 3abh after instruction fsr2h = 03h fsr2l = abh movf move f syntax: movf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: f dest status affected: n, z encoding: 0101 00da ffff ffff description: the contents of register ?f? are moved to a destination dependent upon the status of ?d?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). location ?f? can be anywhere in the 256-byte bank. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write w example: movf reg, 0, 0 before instruction reg = 22h w=ffh after instruction reg = 22h w = 22h
pic18f2585/2680/4585/4680 ds39625b-page 386 preliminary ? 2004 microchip technology inc. movff move f to f syntax: movff f s ,f d operands: 0 f s 4095 0 f d 4095 operation: (f s ) f d status affected: none encoding: 1st word (source) 2nd word (destin.) 1100 1111 ffff ffff ffff ffff fff f s fff f d description: the contents of source register ?f s ? are moved to destination register ?f d ?. location of source ?f s ? can be anywhere in the 4096-byte data space (000h to fffh) and location of destination ?f d ? can also be anywhere from 000h to fffh. either source or destination can be w (a useful special situation). movff is particularly useful for transferring a data memory location to a peripheral register (such as the transmit buffer or an i/o port). the movff instruction cannot use the pcl, tosu, tosh or tosl as the destination register words: 2 cycles: 2 (3) q cycle activity: q1 q2 q3 q4 decode read register ?f? (src) process data no operation decode no operation no dummy read no operation write register ?f? (dest) example: movff reg1, reg2 before instruction reg1 = 33h reg2 = 11h after instruction reg1 = 33h reg2 = 33h movlb move literal to low nibble in bsr syntax: movlw k operands: 0 k 255 operation: k bsr status affected: none encoding: 0000 0001 kkkk kkkk description: the eight-bit literal ?k? is loaded into the bank select register (bsr). the value of bsr<7:4> always remains ? 0 ?, regardless of the value of k 7 :k 4 . words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write literal ?k? to bsr example: movlb 5 before instruction bsr register = 02h after instruction bsr register = 05h
? 2004 microchip technology inc. preliminary ds39625b-page 387 pic18f2585/2680/4585/4680 movlw move literal to w syntax: movlw k operands: 0 k 255 operation: k w status affected: none encoding: 0000 1110 kkkk kkkk description: the eight-bit literal ?k? is loaded into w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: movlw 5ah after instruction w=5ah movwf move w to f syntax: movwf f {,a} operands: 0 f 255 a [0,1] operation: (w) f status affected: none encoding: 0110 111a ffff ffff description: move data from w to register ?f?. location ?f? can be anywhere in the 256-byte bank. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: movwf reg, 0 before instruction w=4fh reg = ffh after instruction w=4fh reg = 4fh
pic18f2585/2680/4585/4680 ds39625b-page 388 preliminary ? 2004 microchip technology inc. mullw multiply literal with w syntax: mullw k operands: 0 k 255 operation: (w) x k prodh:prodl status affected: none encoding: 0000 1101 kkkk kkkk description: an unsigned multiplication is carried out between the contents of w and the 8-bit literal ?k?. the 16-bit result is placed in the prodh:prodl register pair. prodh contains the high byte. w is unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write registers prodh: prodl example: mullw 0c4h before instruction w=e2h prodh = ? prodl = ? after instruction w=e2h prodh = adh prodl = 08h mulwf multiply w with f syntax: mulwf f {,a} operands: 0 f 255 a [0,1] operation: (w) x (f) prodh:prodl status affected: none encoding: 0000 001a ffff ffff description: an unsigned multiplication is carried out between the contents of w and the register file location ?f?. the 16-bit result is stored in the prodh:prodl register pair. prodh contains the high byte. both w and ?f? are unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressi ng mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write registers prodh: prodl example: mulwf reg, 1 before instruction w=c4h reg = b5h prodh = ? prodl = ? after instruction w=c4h reg = b5h prodh = 8ah prodl = 94h
? 2004 microchip technology inc. preliminary ds39625b-page 389 pic18f2585/2680/4585/4680 negf negate f syntax: negf f {,a} operands: 0 f 255 a [0,1] operation: ( f ) + 1 f status affected: n, ov, c, dc, z encoding: 0110 110a ffff ffff description: location ?f? is negated using two?s complement. the result is placed in the data memory location ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: negf reg, 1 before instruction reg = 0011 1010 [3ah] after instruction reg = 1100 0110 [c6h] nop no operation syntax: nop operands: none operation: no operation status affected: none encoding: 0000 1111 0000 xxxx 0000 xxxx 0000 xxxx description: no operation. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation example: none.
pic18f2585/2680/4585/4680 ds39625b-page 390 preliminary ? 2004 microchip technology inc. pop pop top of return stack syntax: pop operands: none operation: (tos) bit bucket status affected: none encoding: 0000 0000 0000 0110 description: the tos value is pulled off the return stack and is discarded. the tos value then becomes the previous value that was pushed onto the return stack. this instruction is provided to enable the user to properly manage the return stack to incorporate a software stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation pop tos value no operation example: pop goto new before instruction tos = 0031a2h stack (1 level down) = 014332h after instruction tos = 014332h pc = new push push top of return stack syntax: push operands: none operation: (pc + 2) tos status affected: none encoding: 0000 0000 0000 0101 description: the pc + 2 is pushed onto the top of the return stack. the previous tos value is pushed down on the stack. this instruction allows implementing a software stack by modifying tos and then pushing it onto the return stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode push pc + 2 onto return stack no operation no operation example: push before instruction tos = 345ah pc = 0124h after instruction pc = 0126h tos = 0126h stack (1 level down) = 345ah
? 2004 microchip technology inc. preliminary ds39625b-page 391 pic18f2585/2680/4585/4680 rcall relative call syntax: rcall n operands: -1024 n 1023 operation: (pc) + 2 tos, (pc) + 2 + 2n pc status affected: none encoding: 1101 1nnn nnnn nnnn description: subroutine call with a jump up to 1k from the current location. first, return address (pc + 2) is pushed onto the stack. then, add the 2?s complement number ?2n? to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? push pc to stack process data write to pc no operation no operation no operation no operation example: here rcall jump before instruction pc = address (here) after instruction pc = address (jump) tos = address (here + 2) reset reset syntax: reset operands: none operation: reset all registers and flags that are affected by a mclr reset. status affected: all encoding: 0000 0000 1111 1111 description: this instruction provides a way to execute a mclr reset in software. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode start reset no operation no operation example: reset after instruction registers = reset value flags* = reset value
pic18f2585/2680/4585/4680 ds39625b-page 392 preliminary ? 2004 microchip technology inc. retfie return from interrupt syntax: retfie {s} operands: s [0,1] operation: (tos) pc, 1 gie/gieh or peie/giel, if s = 1 (ws) w, (statuss) status, (bsrs) bsr, pclatu, pclath are unchanged. status affected: gie/gieh, peie/giel. encoding: 0000 0000 0001 000s description: return from interrupt. stack is popped and top-of-stack (tos) is loaded into the pc. interrupts are enabled by setting either the high or low priority global interrupt enable bit. if ?s? = 1 , the contents of the shadow registers, ws, statuss and bsrs, are loaded into their corresponding registers, w, status and bsr. if ?s? = 0 , no update of these registers occurs (default). words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation pop pc from stack set gieh or giel no operation no operation no operation no operation example: retfie 1 after interrupt pc = tos w=ws bsr = bsrs status = statuss gie/gieh, peie/giel = 1 retlw return literal to w syntax: retlw k operands: 0 k 255 operation: k w, (tos) pc, pclatu, pclath are unchanged status affected: none encoding: 0000 1100 kkkk kkkk description: w is loaded with the eight-bit literal ?k?. the program counter is loaded from the top of the stack (the return address). the high address latch (pclath) remains unchanged. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data pop pc from stack, write to w no operation no operation no operation no operation example: call table ; w contains table ; offset value ; w now has ; table value : table addwf pcl ; w = offset retlw k0 ; begin table retlw k1 ; : : retlw kn ; end of table before instruction w = 07h after instruction w = value of kn
? 2004 microchip technology inc. preliminary ds39625b-page 393 pic18f2585/2680/4585/4680 return return from subroutine syntax: return {s} operands: s [0,1] operation: (tos) pc, if s = 1 (ws) w, (statuss) status, (bsrs) bsr, pclatu, pclath are unchanged status affected: none encoding: 0000 0000 0001 001s description: return from subroutine. the stack is popped and the top of the stack (tos) is loaded into the program counter. if ?s?= 1 , the contents of the shadow registers, ws, statuss and bsrs, are loaded into their corresponding registers, w, status and bsr. if ?s? = 0 , no update of these registers occurs (default). words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation process data pop pc from stack no operation no operation no operation no operation example: return after interrupt pc = tos rlcf rotate left f through carry syntax: rlcf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<7>) c, (c) dest<0> status affected: c, n, z encoding: 0011 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rlcf reg, 0, 0 before instruction reg = 1110 0110 c=0 after instruction reg = 1110 0110 w= 1100 1100 c=1 c register f
pic18f2585/2680/4585/4680 ds39625b-page 394 preliminary ? 2004 microchip technology inc. rlncf rotate left f (no carry) syntax: rlncf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<7>) dest<0> status affected: n, z encoding: 0100 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rlncf reg, 1, 0 before instruction reg = 1010 1011 after instruction reg = 0101 0111 register f rrcf rotate right f through carry syntax: rrcf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<0>) c, (c) dest<7> status affected: c, n, z encoding: 0011 00da ffff ffff description: the contents of register ?f? are rotated one bit to the right through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rrcf reg, 0, 0 before instruction reg = 1110 0110 c=0 after instruction reg = 1110 0110 w= 0111 0011 c=0 c register f
? 2004 microchip technology inc. preliminary ds39625b-page 395 pic18f2585/2680/4585/4680 rrncf rotate right f (no carry) syntax: rrncf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<0>) dest<7> status affected: n, z encoding: 0100 00da ffff ffff description: the contents of register ?f? are rotated one bit to the right. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: rrncf reg, 1, 0 before instruction reg = 1101 0111 after instruction reg = 1110 1011 example 2: rrncf reg, 0, 0 before instruction w=? reg = 1101 0111 after instruction w= 1110 1011 reg = 1101 0111 register f setf set f syntax: setf f {,a} operands: 0 f 255 a [0,1] operation: ffh f status affected: none encoding: 0110 100a ffff ffff description: the contents of the specified register are set to ffh. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: setf reg,1 before instruction reg = 5ah after instruction reg = ffh
pic18f2585/2680/4585/4680 ds39625b-page 396 preliminary ? 2004 microchip technology inc. sleep enter sleep mode syntax: sleep operands: none operation: 00h wdt, 0 wdt postscaler, 1 to , 0 pd status affected: to , pd encoding: 0000 0000 0000 0011 description: the power-down status bit (pd ) is cleared. the time-out status bit (to ) is set. watchdog timer and its postscaler are cleared. the processor is put into sleep mode with the oscillator stopped. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data go to sleep example: sleep before instruction to =? pd =? after instruction to =1 ? pd =0 ? if wdt causes wake-up, this bit is cleared. subfwb subtract f from w with borrow syntax: subfwb f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) ? (f) ? (c ) dest status affected: n, ov, c, dc, z encoding: 0101 01da ffff ffff description: subtract register ?f? and carry flag (borrow) from w (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subfwb reg, 1, 0 before instruction reg = 3 w=2 c=1 after instruction reg = ff w=2 c=0 z=0 n = 1 ; result is negative example 2: subfwb reg, 0, 0 before instruction reg = 2 w=5 c=1 after instruction reg = 2 w=3 c=1 z=0 n = 0 ; result is positive example 3: subfwb reg, 1, 0 before instruction reg = 1 w=2 c=0 after instruction reg = 0 w=2 c=1 z = 1 ; result is zero n=0
? 2004 microchip technology inc. preliminary ds39625b-page 397 pic18f2585/2680/4585/4680 sublw subtract w from literal syntax: sublw k operands: 0 k 255 operation: k ? (w) w status affected: n, ov, c, dc, z encoding: 0000 1000 kkkk kkkk description: w is subtracted from the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example 1: sublw 02h before instruction w = 01h c=? after instruction w = 01h c = 1 ; result is positive z=0 n=0 example 2: sublw 02h before instruction w = 02h c=? after instruction w = 00h c = 1 ; result is zero z=1 n=0 example 3: sublw 02h before instruction w = 03h c=? after instruction w = ffh; (2?s complement) c = 0 ; result is negative z=0 n=1 subwf subtract w from f syntax: subwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? (w) dest status affected: n, ov, c, dc, z encoding: 0101 11da ffff ffff description: subtract w from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subwf reg, 1, 0 before instruction reg = 3 w=2 c=? after instruction reg = 1 w=2 c = 1 ; result is positive z=0 n=0 example 2: subwf reg, 0, 0 before instruction reg = 2 w=2 c=? after instruction reg = 2 w=0 c = 1 ; result is zero z=1 n=0 example 3: subwf reg, 1, 0 before instruction reg = 1 w=2 c=? after instruction reg = ffh ;(2?s complement) w=2 c = 0 ; result is negative z=0 n=1
pic18f2585/2680/4585/4680 ds39625b-page 398 preliminary ? 2004 microchip technology inc. subwfb subtract w from f with borrow syntax: subwfb f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? (w) ? (c ) dest status affected: n, ov, c, dc, z encoding: 0101 10da ffff ffff description: subtract w and the carry flag (borrow) from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subwfb reg, 1, 0 before instruction reg = 19h (0001 1001) w=0dh (0000 1101) c=1 after instruction reg = 0ch (0000 1011) w=0dh (0000 1101) c=1 z=0 n = 0 ; result is positive example 2: subwfb reg, 0, 0 before instruction reg = 1bh (0001 1011) w=1ah (0001 1010) c=0 after instruction reg = 1bh (0001 1011) w = 00h c=1 z = 1 ; result is zero n=0 example 3: subwfb reg, 1, 0 before instruction reg = 03h (0000 0011) w=0eh (0000 1101) c=1 after instruction reg = f5h (1111 0100) ; [2?s comp] w=0eh (0000 1101) c=0 z=0 n = 1 ; result is negative swapf swap f syntax: swapf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f<3:0>) dest<7:4>, (f<7:4>) dest<3:0> status affected: none encoding: 0011 10da ffff ffff description: the upper and lower nibbles of register ?f? are exchanged. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: swapf reg, 1, 0 before instruction reg = 53h after instruction reg = 35h
? 2004 microchip technology inc. preliminary ds39625b-page 399 pic18f2585/2680/4585/4680 tblrd table read syntax: tblrd ( *; *+; *-; +*) operands: none operation: if tblrd *, (prog mem (tblptr)) tablat; tblptr ? no change; if tblrd *+, (prog mem (tblptr)) tablat; (tblptr) + 1 tblptr; if tblrd *-, (prog mem (tblptr)) tablat; (tblptr) ? 1 tblptr; if tblrd +*, (tblptr) + 1 tblptr; (prog mem (tblptr)) tablat; status affected: none encoding: 0000 0000 0000 10nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction is used to read the contents of program memory (p.m.). to address the program memory, a pointer, called table pointer (tblptr), is used. the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbyte address range. tblptr[0] = 0 : least significant byte of program memory word tblptr[0] = 1 : most significant byte of program memory word the tblrd instruction can modify the value of tblptr as follows:  no change  post-increment  post-decrement  pre-increment words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read program memory) no operation no operation (write tablat) tblrd table read (continued) example 1: tblrd *+ ; before instruction tablat = 55h tblptr = 00a356h memory(00a356h) = 34h after instruction tablat = 34h tblptr = 00a357h example 2: tblrd +* ; before instruction tablat = 0aah tblptr = 01a357h memory(01a357h) = 12h memory(01a358h) = 34h after instruction tablat = 34h tblptr = 01a358h
pic18f2585/2680/4585/4680 ds39625b-page 400 preliminary ? 2004 microchip technology inc. tblwt table write syntax: tblwt ( *; *+; *-; +*) operands: none operation: if tblwt*, (tablat) holding register; tblptr ? no change; if tblwt*+, (tablat) holding register; (tblptr) + 1 tblptr; if tblwt*-, (tablat) holding register; (tblptr) ? 1 tblptr; if tblwt+*, (tblptr) + 1 tblptr; (tablat) holding register; status affected: none encoding: 0000 0000 0000 11nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction uses the 3 lsbs of the tblptr to determine which of the 8 holding registers the tablat is written to. the holding registers are used to program the contents of program memory (p.m.). (refer to section 6.0 ?flash program memory? for additional details on programming flash memory.) the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbtye address range. the lsb of the tblptr selects which byte of the program memory location to access. tblptr[0] = 0 : least significant byte of program memory word tblptr[0] = 1 : most significant byte of program memory word the tblwt instruction can modify the value of tblptr as follows:  no change  post-increment  post-decrement  pre-increment words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read tablat) no operation no operation (write to holding register ) tblwt table write (continued) example 1: tblwt *+; before instruction tablat = 55h tblptr = 00a356h holding register (00a356h) = ffh after instructions (table write completion) tablat = 55h tblptr = 00a357h holding register (00a356h) = 55h example 2: tblwt +*; before instruction tablat = 34h tblptr = 01389ah holding register (01389ah) = ffh holding register (01389bh) = ffh after instruction (table write completion) tablat = 34h tblptr = 01389bh holding register (01389ah) = ffh holding register (01389bh) = 34h
? 2004 microchip technology inc. preliminary ds39625b-page 401 pic18f2585/2680/4585/4680 tstfsz test f, skip if 0 syntax: tstfsz f {,a} operands: 0 f 255 a [0,1] operation: skip if f = 0 status affected: none encoding: 0110 011a ffff ffff description: if ?f? = 0 , the next instruction fetched during the current instruction execution is discarded and a nop is executed, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here tstfsz cnt, 1 nzero : zero : before instruction pc = address (here) after instruction if cnt = 00h, pc = address (zero) if cnt 00h, pc = address (nzero) xorlw exclusive or literal with w syntax: xorlw k operands: 0 k 255 operation: (w) .xor. k w status affected: n, z encoding: 0000 1010 kkkk kkkk description: the contents of w are xored with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: xorlw 0afh before instruction w=b5h after instruction w=1ah
pic18f2585/2680/4585/4680 ds39625b-page 402 preliminary ? 2004 microchip technology inc. xorwf exclusive or w with f syntax: xorwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) .xor. (f) dest status affected: n, z encoding: 0001 10da ffff ffff description: exclusive or the contents of w with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in the register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 25.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: xorwf reg, 1, 0 before instruction reg = afh w=b5h after instruction reg = 1ah w=b5h
? 2004 microchip technology inc. preliminary ds39625b-page 403 pic18f2585/2680/4585/4680 25.2 extended instruction set in addition to the standard 75 instructions of the pic18 instruction set, pic18f2585/2680/4585/4680 devices also provide an optional extension to the core cpu functionality. the added features include eight additional instructions that augment indirect and indexed addressing operations and the implementation of indexed literal offset addressing mode for many of the standard pic18 instructions. the additional features are disabled by default. to enable them, users must set the xinst configuration bit. the instructions in the extended set can all be classified as literal operations, which either manipulate the file select registers or use them for indexed addressing. two of the instructions, addfsr and subfsr , each have an additional special instantiation for using fsr2. these versions ( addulnk and subulnk ) allow for automatic return after execution. the extended instructions are specifically implemented to optimize re-entrant program code (that is, code that is recursive or that uses a software stack) written in high-level languages, particularly c. among other things, they allow users working in high-level languages to perform certain operations on data structures more efficiently. these include:  dynamic allocation and de-allocation of software stack space when entering and leaving subroutines  function pointer invocation  software stack pointer manipulation  manipulation of variables located in a software stack a summary of the instructions in the extended instruc- tion set is provided in table 25-3. detailed descriptions are provided in section 25.2.2 ?extended instruction set? . the opcode field descriptions in table 25-1 apply to both the standard and extended pic18 instruction sets. 25.2.1 extended instruction syntax most of the extended instructions use indexed arguments, using one of the file select registers and some offset to specify a source or destination register. when an argument for an instruction serves as part of indexed addressing, it is enclosed in square brackets (?[ ]?). this is done to indicate that the argument is used as an index or offset. mpasm? assembler will flag an error if it determines that an index or offset value is not bracketed. when the extended instruction set is enabled, brackets are also used to indicate index arguments in bit- oriented and byte-oriented instructions. this is in addition to other changes in their syntax. for more details, see section 25.2.3.1 ?extended instruction syntax with standard pic18 commands? . table 25-3: extensions to the pic18 instruction set note: the instruction set extension and the indexed literal offset addressing mode were designed for optimizing applications written in c; the user may likely never use these instructions directly in assembler. the syntax for these commands is pro- vided as a reference for users who may be reviewing code that has been generated by a compiler. note: in the past, square brackets have been used to denote optional arguments in the pic18 and earlier instruction sets. in this text and going forward, optional arguments are denoted by braces (?{ }?). mnemonic, operands description cycles 16-bit instruction word status affected msb lsb addfsr addulnk callw movsf movss pushl subfsr subulnk f, k k z s , f d z s , z d k f, k k add literal to fsr add literal to fsr2 and return call subroutine using wreg move z s (source) to 1st word f d (destination) 2nd word move z s (source) to 1st word z d (destination) 2nd word store literal at fsr2, decrement fsr2 subtract literal from fsr subtract literal from fsr2 and return 1 2 2 2 2 1 1 2 1110 1110 0000 1110 1111 1110 1111 1110 1110 1110 1000 1000 0000 1011 ffff 1011 xxxx 1010 1001 1001 ffkk 11kk 0001 0zzz ffff 1zzz xzzz kkkk ffkk 11kk kkkk kkkk 0100 zzzz ffff zzzz zzzz kkkk kkkk kkkk none none none none none none none none
pic18f2585/2680/4585/4680 ds39625b-page 404 preliminary ? 2004 microchip technology inc. 25.2.2 extended instruction set addfsr add literal to fsr syntax: addfsr f, k operands: 0 k 63 f [ 0, 1, 2 ] operation: fsr(f) + k fsr(f) status affected: none encoding: 1110 1000 ffkk kkkk description: the 6-bit literal ?k? is added to the contents of the fsr specified by ?f?. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to fsr example: addfsr 2, 23h before instruction fsr2 = 03ffh after instruction fsr2 = 0422h addulnk add literal to fsr2 and return syntax: addulnk k operands: 0 k 63 operation: fsr2 + k fsr2, pc = (tos) status affected: none encoding: 1110 1000 11kk kkkk description: the 6-bit literal ?k? is added to the contents of fsr2. a return is then executed by loading the pc with the tos. the instruction takes two cycles to execute; a nop is performed during the second cycle. this may be thought of as a special case of the addfsr instruction, where f = 3 (binary ? 11 ?); it operates only on fsr2. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to fsr no operation no operation no operation no operation example: addulnk 23h before instruction fsr2 = 03ffh pc = 0100h tos = 02afh after instruction fsr2 = 0422h pc = 02afh tos = tos ? 1 note: all pic18 instructions may take an optional label argument preceding the instruction mnemonic for use in symbolic addressing. if a label is used, the instruction syntax then becomes: {label} instruction argument(s).
? 2004 microchip technology inc. preliminary ds39625b-page 405 pic18f2585/2680/4585/4680 callw subroutine call using wreg syntax: callw operands: none operation: (pc + 2) tos, (w) pcl, (pclath) pch, (pclatu) pcu status affected: none encoding: 0000 0000 0001 0100 description first, the return address (pc + 2) is pushed onto the return stack. next, the contents of w are written to pcl; the existing value is discarded. then, the contents of pclath and pclatu are latched into pch and pcu, respectively. the second cycle is executed as a nop instruction while the new next instruction is fetched. unlike call , there is no option to update w, status or bsr. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read wreg push pc to stack no operation no operation no operation no operation no operation example: here callw before instruction pc = address (here) pclath = 10h pclatu = 00h w = 06h after instruction pc = 001006h tos = address (here + 2) pclath = 10h pclatu = 00h w = 06h movsf move indexed to f syntax: movsf [z s ], f d operands: 0 z s 127 0 f d 4095 operation: ((fsr2) + z s ) f d status affected: none encoding: 1st word (source) 2nd word (destin.) 1110 1111 1011 ffff 0zzz ffff zzzz s ffff d description: the contents of the source register are moved to destination register ?f d ?. the actual address of the source register is determined by adding the 7-bit literal offset ?z s ? in the first word to the value of fsr2. the address of the destination register is specified by the 12-bit literal ?f d ? in the second word. both addresses can be anywhere in the 4096-byte data space (000h to fffh). the movsf instruction cannot use the pcl, tosu, tosh or tosl as the destination register. if the resultant source address points to an indirect addressing register, the value returned will be 00h. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode determine source addr determine source addr read source reg decode no operation no dummy read no operation write register ?f? (dest) example: movsf [05h], reg2 before instruction fsr2 = 80h contents of 85h = 33h reg2 = 11h after instruction fsr2 = 80h contents of 85h = 33h reg2 = 33h
pic18f2585/2680/4585/4680 ds39625b-page 406 preliminary ? 2004 microchip technology inc. movss move indexed to indexed syntax: movss [z s ], [z d ] operands: 0 z s 127 0 z d 127 operation: ((fsr2) + z s ) ((fsr2) + z d ) status affected: none encoding: 1st word (source) 2nd word (dest.) 1110 1111 1011 xxxx 1zzz xzzz zzzz s zzzz d description the contents of the source register are moved to the destination register. the addresses of the source and destination registers are determined by adding the 7-bit literal offsets ?z s ? or ?z d ?, respectively, to the value of fsr2. both registers can be located anywhere in the 4096-byte data memory space (000h to fffh). the movss instruction cannot use the pcl, tosu, tosh or tosl as the destination register. if the resultant source address points to an indirect addressing register, the value returned will be 00h. if the resultant destination address points to an indirect addressing register, the instruction will execute as a nop . words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode determine source addr determine source addr read source reg decode determine dest addr determine dest addr write to dest reg example: movss [05h], [06h] before instruction fsr2 = 80h contents of 85h = 33h contents of 86h = 11h after instruction fsr2 = 80h contents of 85h = 33h contents of 86h = 33h pushl store literal at fsr2, decrement fsr2 syntax: pushl k operands: 0 k 255 operation: k (fsr2), fsr2 ? 1 fsr2 status affected: none encoding: 1111 1010 kkkk kkkk description: the 8-bit literal ?k? is written to the data memory address specified by fsr2. fsr2 is decremented by 1 after the operation. this instruction allows users to push values onto a software stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write to destination example: pushl 08h before instruction fsr2h:fsr2l = 01ech memory (01ech) = 00h after instruction fsr2h:fsr2l = 01ebh memory (01ech) = 08h
? 2004 microchip technology inc. preliminary ds39625b-page 407 pic18f2585/2680/4585/4680 subfsr subtract literal from fsr syntax: subfsr f, k operands: 0 k 63 f [ 0, 1, 2 ] operation: fsrf ? k fsrf status affected: none encoding: 1110 1001 ffkk kkkk description: the 6-bit literal ?k? is subtracted from the contents of the fsr specified by ?f?. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: subfsr 2, 23h before instruction fsr2 = 03ffh after instruction fsr2 = 03dch subulnk subtract literal from fsr2 and return syntax: subulnk k operands: 0 k 63 operation: fsr2 ? k fsr2 (tos) pc status affected: none encoding: 1110 1001 11kk kkkk description: the 6-bit literal ?k? is subtracted from the contents of the fsr2. a return is then executed by loading the pc with the tos. the instruction takes two cycles to execute; a nop is performed during the second cycle. this may be thought of as a special case of the subfsr instruction, where f = 3 (binary ? 11 ?); it operates only on fsr2. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination no operation no operation no operation no operation example: subulnk 23h before instruction fsr2 = 03ffh pc = 0100h after instruction fsr2 = 03dch pc = (tos)
pic18f2585/2680/4585/4680 ds39625b-page 408 preliminary ? 2004 microchip technology inc. 25.2.3 byte-oriented and bit-oriented instructions in indexed literal offset mode in addition to eight new commands in the extended set, enabling the extended instruction set also enables indexed literal offset addressing mode ( section 5.6.1 ?indexed addressing with literal offset? ). this has a significant impact on the way that many commands of the standard pic18 instruction set are interpreted. when the extended set is disabled, addresses embed- ded in opcodes are treated as literal memory locations: either as a location in the access bank (a = 0 ), or in a gpr bank designated by the bsr (a = 1 ). when the extended instruction set is enabled and a = 0 , however, a file register argument of 5fh or less is interpreted as an offset from the pointer value in fsr2 and not as a literal address. for practical purposes, this means that all instructions that use the access ram bit as an argument ? that is, all bit-oriented and byte-oriented instructions, or almost half of the core pic18 instructions ? may behave differently when the extended instruction set is enabled. when the content of fsr2 is 00h, the boundaries of the access ram are essentially remapped to their original values. this may be useful in creating backward compatible code. if this technique is used, it may be necessary to save the value of fsr2 and restore it when moving back and forth between ?c? and assembly routines in order to preserve the stack pointer. users must also keep in mind the syntax requirements of the extended instruction set (see section 25.2.3.1 ?extended instruction syntax with standard pic18 commands? ). although the indexed literal offset addressing mode can be very useful for dynamic stack and pointer manipulation, it can also be very annoying if a simple arithmetic operation is carried out on the wrong register. users who are accustomed to the pic18 programming must keep in mind that, when the extended instruction set is enabled, register addresses of 5fh or less are used for indexed literal offset addressing. representative examples of typical byte-oriented and bit-oriented instructions in the indexed literal offset addressing mode are provided on the following page to show how execution is affected. the operand conditions shown in the examples are applicable to all instructions of these types. 25.2.3.1 extended instruction syntax with standard pic18 commands when the extended instruction set is enabled, the file register argument, ?f?, in the standard byte-oriented and bit-oriented commands, is replaced with the literal off- set value, ?k?. as already noted, this occurs only when ?f? is less than or equal to 5fh. when an offset value is used, it must be indicated by square brackets (?[ ]?). as with the extended instructions, the use of brackets indi- cates to the compiler that the value is to be interpreted as an index or an offset. omitting the brackets, or using a value greater than 5fh within brackets, will generate an error in the mpasm? assembler. if the index argument is properly bracketed for indexed literal offset addressing, the access ram argument is never specified; it will automatically be assumed to be ? 0 ?. this is in contrast to standard operation (extended instruction set disabled) when ?a? is set on the basis of the target address. declaring the access ram bit in this mode will also generate an error in the mpasm assembler. the destination argument, ?d?, functions as before. in the latest versions of the mpasm assembler, language support for the extended instruction set must be explicitly invoked. this is done with either the command line option, /y , or the pe directive in the source listing. 25.2.4 considerations when enabling the extended instruction set it is important to note that the extensions to the instruc- tion set may not be beneficial to all users. in particular, users who are not writing code that uses a software stack may not benefit from using the extensions to the instruction set. additionally, the indexed literal offset addressing mode may create issues with legacy applications written to the pic18 assembler. this is because instructions in the legacy code may attempt to address registers in the access bank below 5fh. since these addresses are interpreted as literal offsets to fsr2 when the instruction set extension is enabled, the application may read or write to the wrong data addresses. when porting an application to the pic18f2585/2680/ 4585/4680, it is very important to consider the type of code. a large, re-entrant application that is written in ?c? and would benefit from efficient compilation will do well when using the instruction set extensions. legacy applications that heavily use the access bank will most likely not benefit from using the extended instruction set. note: enabling the pic18 instruction set extension may cause legacy applications to behave erratically or fail entirely.
? 2004 microchip technology inc. preliminary ds39625b-page 409 pic18f2585/2680/4585/4680 addwf add w to indexed (indexed literal offset mode) syntax: addwf [k] {,d} operands: 0 k 95 d [0,1] a = 0 operation: (w) + ((fsr2) + k) dest status affected: n, ov, c, dc, z encoding: 0010 01d0 kkkk kkkk description: the contents of w are added to the contents of the register indicated by fsr2, offset by the value ?k?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write to destination example: addwf [ofst] ,0 before instruction w = 17h ofst = 2ch fsr2 = 0a00h contents of 0a2ch = 20h after instruction w = 37h contents of 0a2ch = 20h bsf bit set indexed (indexed literal offset mode) syntax: bsf [k], b operands: 0 f 95 0 b 7 a = 0 operation: 1 ((fsr2 + k)) status affected: none encoding: 1000 bbb0 kkkk kkkk description: bit ?b? of the register indicated by fsr2, offset by the value ?k?, is set. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: bsf [flag_ofst], 7 before instruction flag_ofst = 0ah fsr2 = 0a00h contents of 0a0ah = 55h after instruction contents of 0a0ah = d5h setf set indexed (indexed literal offset mode) syntax: setf [k] operands: 0 k 95 operation: ffh ((fsr2) + k) status affected: none encoding: 0110 1000 kkkk kkkk description: the contents of the register indicated by fsr2, offset by ?k?, are set to ffh. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write register example: setf [ofst] before instruction ofst = 2ch fsr2 = 0a00h contents of 0a2ch = 00h after instruction contents of 0a2ch = ffh
pic18f2585/2680/4585/4680 ds39625b-page 410 preliminary ? 2004 microchip technology inc. 25.2.5 special considerations with microchip mplab ? ide tools the latest versions of microchip?s software tools have been designed to fully support the extended instruction set of the pic18f2585/2680/4585/4680 family of devices. this includes the mplab c18 c compiler, mpasm assembly language and mplab integrated development environment (ide). when selecting a target device for software develop- ment, mplab ide will automatically set default configuration bits for that device. the default setting for the xinst configuration bit is ? 0 ?, disabling the extended instruction set and indexed literal offset addressing mode. for proper execution of applications developed to take advantage of the extended instruction set, xinst must be set during programming. to develop software for the extended instruction set, the user must enable support for the instructions and the indexed addressing mode in their language tool(s). depending on the environment being used, this may be done in several ways:  a menu option, or dialog box within the environment, that allows the user to configure the language tool and its settings for the project  a command line option  a directive in the source code these options vary between different compilers, assemblers and development environments. users are encouraged to review the documentation accompany- ing their development systems for the appropriate information.
? 2004 microchip technology inc. preliminary ds39625b-page 411 pic18f2585/2680/4585/4680 26.0 development support the picmicro ? microcontrollers are supported with a full range of hardware and software development tools:  integrated development environment - mplab ? ide software  assemblers/compilers/linkers - mpasm tm assembler - mplab c17 and mplab c18 c compilers -mplink tm object linker/ mplib tm object librarian - mplab c30 c compiler - mplab asm30 assembler/linker/library  simulators - mplab sim software simulator - mplab dspic30 software simulator emulators - mplab ice 2000 in-circuit emulator - mplab ice 4000 in-circuit emulator  in-circuit debugger - mplab icd 2  device programmers -pro mate ? ii universal device programmer - picstart ? plus development programmer - mplab pm3 device programmer  low-cost demonstration boards - picdem tm 1 demonstration board - picdem.net tm demonstration board - picdem 2 plus demonstration board - picdem 3 demonstration board - picdem 4 demonstration board - picdem 17 demonstration board - picdem 18r demonstration board - picdem lin demonstration board - picdem usb demonstration board  evaluation kits -k ee l oq ? evaluation and programming tools - picdem msc -microid ? developer kits -can - powersmart ? developer kits -analog 26.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16-bit micro- controller market. the mplab ide is a windows ? based application that contains:  an interface to debugging tools - simulator - programmer (sold separately) - emulator (sold separately) - in-circuit debugger (sold separately)  a full-featured editor with color coded context  a multiple project manager  customizable data windows with direct edit of contents  high-level source code debugging  mouse over variable inspection  extensive on-line help the mplab ide allows you to:  edit your source files (either assembly or c)  one touch assemble (or compile) and download to picmicro emulator and simulator tools (automatically updates all project information)  debug using: - source files (assembly or c) - mixed assembly and c - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increasing flexibility and power. 26.2 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for all picmicro mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol ref- erence, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include:  integration into mplab ide projects  user defined macros to streamline assembly code  conditional assembly for multi-purpose source files  directives that allow complete control over the assembly process
pic18f2585/2680/4585/4680 ds39625b-page 412 preliminary ? 2004 microchip technology inc. 26.3 mplab c17 and mplab c18 c compilers the mplab c17 and mplab c18 code development systems are complete ansi c compilers for microchip?s pic17cxxx and pic18cxxx family of microcontrollers. these compilers provide powerful integration capabilities, superior code optimization and ease of use not found with other compilers. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 26.4 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c17 and mplab c18 c compilers. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include:  efficient linking of single libraries instead of many smaller files  enhanced code maintainability by grouping related modules together  flexible creation of libraries with easy module listing, replacement, deletion and extraction 26.5 mplab c30 c compiler the mplab c30 c compiler is a full-featured, ansi compliant, optimizing compiler that translates standard ansi c programs into dspic30f assembly language source. the compiler also supports many command line options and language extensions to take full advantage of the dspic30f device hardware capabili- ties and afford fine control of the compiler code generator. mplab c30 is distributed with a complete ansi c standard library. all library functions have been vali- dated and conform to the ansi c library standard. the library includes functions for string manipulation, dynamic memory allocation, data conversion, time- keeping and math functions (trigonometric, exponential and hyperbolic). the compiler provides symbolic information for high-level source debugging with the mplab ide. 26.6 mplab asm30 assembler, linker and librarian mplab asm30 assembler produces relocatable machine code from symbolic assembly language for dspic30f devices. mplab c30 compiler uses the assembler to produce it?s object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include:  support for the entire dspic30f instruction set  support for fixed-point and floating-point data  command line interface  rich directive set  flexible macro language  mplab ide compatibility 26.7 mplab sim software simulator the mplab sim software simulator allows code devel- opment in a pc hosted environment by simulating the picmicro series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user defined key press, to any pin. the execu- tion can be performed in single-step, execute until break or trace mode. the mplab sim simulator fully supports symbolic debugging using the mplab c17 and mplab c18 c compilers, as well as the mpasm assembler. the software simulator offers the flexibility to develop and debug code outside of the laboratory environment, making it an excellent, economical software development tool. 26.8 mplab sim30 software simulator the mplab sim30 software simulator allows code development in a pc hosted environment by simulating the dspic30f series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user defined key press, to any of the pins. the mplab sim30 simulator fully supports symbolic debugging using the mplab c30 c compiler and mplab asm30 assembler. the simulator runs in either a command line mode for automated tasks, or from mplab ide. this high-speed simulator is designed to debug, analyze and optimize time intensive dsp routines.
? 2004 microchip technology inc. preliminary ds39625b-page 413 pic18f2585/2680/4585/4680 26.9 mplab ice 2000 high-performance universal in-circuit emulator the mplab ice 2000 universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for picmicro microcontrollers. software control of the mplab ice 2000 in-circuit emulator is advanced by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab ice 2000 is a full-featured emulator sys- tem with enhanced trace, trigger and data monitoring features. interchangeable processor modules allow the system to be easily reconfigured for emulation of differ- ent processors. the universal architecture of the mplab ice in-circuit emulator allows expansion to support new picmicro microcontrollers. the mplab ice 2000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft ? windows 32-bit operating system were chosen to best make these features available in a simple, unified application. 26.10 mplab ice 4000 high-performance universal in-circuit emulator the mplab ice 4000 universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for high- end picmicro microcontrollers. software control of the mplab ice in-circuit emulator is provided by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab icd 4000 is a premium emulator system, providing the features of mplab ice 2000, but with increased emulation memory and high-speed perfor- mance for dspic30f and pic18xxxx devices. its advanced emulator features include complex triggering and timing, up to 2 mb of emulation memory and the ability to view variables in real-time. the mplab ice 4000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft windows 32-bit operating system were chosen to best make these features available in a simple, unified application. 26.11 mplab icd 2 in-circuit debugger microchip?s in-circuit debugger, mplab icd 2, is a powerful, low-cost, run-time development tool, connecting to the host pc via an rs-232 or high-speed usb interface. this tool is based on the flash picmicro mcus and can be used to develop for these and other picmicro microcontrollers. the mplab icd 2 utilizes the in-circuit debugging capability built into the flash devices. this feature, along with microchip?s in-circuit serial programming tm (icsp tm ) protocol, offers cost effective in-circuit flash debugging from the graphical user interface of the mplab integrated development environment. this enables a designer to develop and debug source code by setting breakpoints, single-stepping and watching variables, cpu status and peripheral registers. running at full speed enables testing hardware and applications in real-time. mplab icd 2 also serves as a development programmer for selected picmicro devices. 26.12 pro mate ii universal device programmer the pro mate ii is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features an lcd display for instructions and error messages and a modular detachable socket assembly to support various package types. in stand-alone mode, the pro mate ii device programmer can read, verify and program picmicro devices without a pc connection. it can also set code protection in this mode. 26.13 mplab pm3 device programmer the mplab pm3 is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modular detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand- alone mode, the mplab pm3 device programmer can read, verify and program picmicro devices without a pc connection. it can also set code protection in this mode. mplab pm3 connects to the host pc via an rs- 232 or usb cable. mplab pm3 has high-speed com- munications and optimized algorithms for quick pro- gramming of large memory devices and incorporates an sd/mmc card for file storage and secure data appli- cations.
pic18f2585/2680/4585/4680 ds39625b-page 414 preliminary ? 2004 microchip technology inc. 26.14 picstart plus development programmer the picstart plus development programmer is an easy-to-use, low-cost, prototype programmer. it con- nects to the pc via a com (rs-232) port. mplab integrated development environment software makes using the programmer simple and efficient. the picstart plus development programmer supports most picmicro devices up to 40 pins. larger pin count devices, such as the pic16c92x and pic17c76x, may be supported with an adapter socket. the picstart plus development programmer is ce compliant. 26.15 picdem 1 picmicro demonstration board the picdem 1 demonstration board demonstrates the capabilities of the pic16c5x (pic16c54 to pic16c58a), pic16c61, pic16c62x, pic16c71, pic16c8x, pic17c42, pic17c43 and pic17c44. all necessary hardware and software is included to run basic demo programs. the sample microcontrollers provided with the picdem 1 demonstration board can be programmed with a pro mate ii device program- mer or a picstart plus development programmer. the picdem 1 demonstration board can be connected to the mplab ice in-circuit emulator for testing. a prototype area extends the circuitry for additional appli- cation components. features include an rs-232 interface, a potentiometer for simulated analog input, push button switches and eight leds. 26.16 picdem.net internet/ethernet demonstration board the picdem.net demonstration board is an internet/ ethernet demonstration board using the pic18f452 microcontroller and tcp/ip firmware. the board supports any 40-pin dip device that conforms to the standard pinout used by the pic16f877 or pic18c452. this kit features a user friendly tcp/ip stack, web server with html, a 24l256 serial eeprom for xmodem download to web pages into serial eeprom, icsp/mplab icd 2 interface con- nector, an ethernet interface, rs-232 interface and a 16 x 2 lcd display. also included is the book and cd-rom ?tcp/ip lean, web servers for embedded systems,? by jeremy bentham 26.17 picdem 2 plus demonstration board the picdem 2 plus demonstration board supports many 18, 28 and 40-pin microcontrollers, including pic16f87x and pic18fxx2 devices. all the neces- sary hardware and software is included to run the dem- onstration programs. the sample microcontrollers provided with the picdem 2 demonstration board can be programmed with a pro mate ii device program- mer, picstart plus development programmer, or mplab icd 2 with a universal programmer adapter. the mplab icd 2 and mplab ice in-circuit emulators may also be used with the picdem 2 demonstration board to test firmware. a prototype area extends the circuitry for additional application components. some of the features include an rs-232 interface, a 2 x 16 lcd display, a piezo speaker, an on-board temperature sensor, four leds and sample pic18f452 and pic16f877 flash microcontrollers. 26.18 picdem 3 pic16c92x demonstration board the picdem 3 demonstration board supports the pic16c923 and pic16c924 in the plcc package. all the necessary hardware and software is included to run the demonstration programs. 26.19 picdem 4 8/14/18-pin demonstration board the picdem 4 can be used to demonstrate the capa- bilities of the 8, 14 and 18-pin pic16xxxx and pic18xxxx mcus, including the pic16f818/819, pic16f87/88, pic16f62xa and the pic18f1320 family of microcontrollers. picdem 4 is intended to showcase the many features of these low pin count parts, including lin and motor control using eccp. special provisions are made for low-power operation with the supercapacitor circuit and jumpers allow on- board hardware to be disabled to eliminate current draw in this mode. included on the demo board are pro- visions for crystal, rc or canned oscillator modes, a five volt regulator for use with a nine volt wall adapter or battery, db-9 rs-232 interface, icd connector for programming via icsp and development with mplab icd 2, 2 x 16 liquid crystal display, pcb footprints for h-bridge motor driver, lin transceiver and eeprom. also included are: header for expansion, eight leds, four potentiometers, three push buttons and a proto- typing area. included with the kit is a pic16f627a and a pic18f1320. tutorial firmware is included along with the user?s guide.
? 2004 microchip technology inc. preliminary ds39625b-page 415 pic18f2585/2680/4585/4680 26.20 picdem 17 demonstration board the picdem 17 demonstration board is an evaluation board that demonstrates the capabilities of several microchip microcontrollers, including pic17c752, pic17c756a, pic17c762 and pic17c766. a pro- grammed sample is included. the pro mate ii device programmer, or the picstart plus development pro- grammer, can be used to reprogram the device for user tailored application development. the picdem 17 demonstration board supports program download and execution from external on-board flash memory. a generous prototype area is available for user hardware expansion. 26.21 picdem 18r pic18c601/801 demonstration board the picdem 18r demonstration board serves to assist development of the pic18c601/801 family of microchip microcontrollers. it provides hardware implementation of both 8-bit multiplexed/demultiplexed and 16-bit memory modes. the board includes 2 mb external flash memory and 128 kb sram memory, as well as serial eeprom, allowing access to the wide range of memory types supported by the pic18c601/801. 26.22 picdem lin pic16c43x demonstration board the powerful lin hardware and software kit includes a series of boards and three picmicro microcontrollers. the small footprint pic16c432 and pic16c433 are used as slaves in the lin communication and feature on-board lin transceivers. a pic16f874 flash microcontroller serves as the master. all three micro- controllers are programmed with firmware to provide lin bus communication. 26.23 pickit tm 1 flash starter kit a complete ?development system in a box?, the pickit? flash starter kit includes a convenient multi-section board for programming, evaluation and development of 8/14-pin flash pic ? microcontrollers. powered via usb, the board operates under a simple windows gui. the pickit 1 starter kit includes the user?s guide (on cd rom), pickit 1 tutorial software and code for various applications. also included are mplab ? ide (integrated development environment) software, software and hardware ?tips 'n tricks for 8-pin flash pic ? microcontrollers? handbook and a usb interface cable. supports all current 8/14-pin flash pic microcontrollers, as well as many future planned devices. 26.24 picdem usb pic16c7x5 demonstration board the picdem usb demonstration board shows off the capabilities of the pic16c745 and pic16c765 usb microcontrollers. this board provides the basis for future usb products. 26.25 evaluation and programming tools in addition to the picdem series of circuits, microchip has a line of evaluation kits and demonstration software for these products. k ee l oq evaluation and programming tools for microchip?s hcs secure data products  can developers kit for automotive network applications  analog design boards and filter design software  powersmart battery charging evaluation/ calibration kits irda ? development kit  microid development and rflab tm development software  seeval ? designer kit for memory evaluation and endurance calculations  picdem msc demo boards for switching mode power supply, high-power ir driver, delta sigma adc and flow rate sensor check the microchip web page and the latest product selector guide for the complete list of demonstration and evaluation kits.
pic18f2585/2680/4585/4680 ds39625b-page 416 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 417 pic18f2585/2680/4585/4680 27.0 electrical characteristics absolute maximum ratings (?) ambient temperature under bias................................................................................................. ............-40c to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on any pin with respect to v ss (except v dd and m clr ) ................................................... -0.3v to (v dd + 0.3v) voltage on v dd with respect to v ss ......................................................................................................... -0.3v to +7.5v voltage on mclr with respect to v ss (note 2) ......................................................................................... 0v to +13.25v voltage on ra4 with respect to v ss ............................................................................................................... 0v to +8.5v total power dissipation (note 1) ............................................................................................................................... 1.0w maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ........................................................................................................................... ...250 ma input clamp current, i ik (v i < 0 or v i > v dd ) ...................................................................................................................... 20 ma output clamp current, i ok (v o < 0 or v o > v dd ) .............................................................................................................. 20 ma maximum output current sunk by any i/o pin..................................................................................... .....................25 ma maximum output current sourced by any i/o pin .................................................................................. ..................25 ma maximum current sunk by all ports ...................................................................................................................... .200 ma maximum current sourced by all ports ........................................................................................... .......................200 ma note 1: power dissipation is calculated as follows: pdis = v dd x {i dd ? i oh } + {(v dd ? v oh ) x i oh } + (v ol x i ol ) 2: voltage spikes below v ss at the mclr /v pp pin, inducing currents greater than 80 ma, may cause latch-up. thus, a series resistor of 50-100 ? should be used when applying a ?low? level to the mclr /v pp /re3 pin, rather than pulling this pin directly to v ss . ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic18f2585/2680/4585/4680 ds39625b-page 418 preliminary ? 2004 microchip technology inc. figure 27-1: pic18f2585/2680/4585/4680 voltage-frequency graph (industrial) figure 27-2: pic18lf2585/2680/4585/4680 voltage-frequency graph (industrial) frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v 40 mhz 5.0v 3.5v 3.0v 2.5v pic18fx585/x680 4.2v frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v 40 mhz 5.0v 3.5v 3.0v 2.5v pic18lfx585/x680 f max = (16.36 mhz/v) (v ddappmin ? 2.0v) + 4 mhz note: v ddappmin is the minimum voltage of the picmicro ? device in the application. 4 mhz 4.2v
? 2004 microchip technology inc. preliminary ds39625b-page 419 pic18f2585/2680/4585/4680 27.1 dc characteristics: supply voltage pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f2585/2680/4585/4680 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min typ max units conditions v dd supply voltage d001 pic18lfx585/x680 2.0 ? 5.5 v hs, xt, rc and lp oscillator mode pic18fx585/x680 4.2 ? 5.5 v d002 v dr ram data retention voltage (1) 1.5 ? ? v d003 v por v dd start voltage to ensure internal power-on reset signal ? ? 0.7 v see section on power-on reset for details d004 s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section on power-on reset for details v bor brown-out reset voltage d005 borv1:borv0 = 11 1.96 2.06 2.16 v borv1:borv0 = 10 2.64 2.78 2.92 v borv1:borv0 = 01 4.11 4.33 4.55 v borv1:borv0 = 00 4.41 4.64 4.87 v legend: shading of rows is to assist in readability of the table. note 1: this is the limit to which v dd can be lowered in sleep mode, or duri ng a device reset, without losing ram data.
pic18f2585/2680/4585/4680 ds39625b-page 420 preliminary ? 2004 microchip technology inc. 27.2 dc characteristics: power-down and supply current pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f2585/2680/4585/4680 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions power-down current (i pd ) (1) pic18lfx585/x680 0.25 0.95 a -40c v dd = 2.0v, ( sleep mode) 0.3 1.0 a +25c 3.0 6.0 a +85c pic18lfx585/x680 0.3 1.4 a -40c v dd = 3.0v, ( sleep mode) 0.35 2.0 a +25c 3.5 8.0 a +85c all devices 0.5 1.9 a -40c v dd = 5.0v, ( sleep mode) 0.5 2.0 a +25c 6.0 15 a +85c legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? . 4: standard low-cost 32 khz crystals have an operating temper ature range of -10c to + 70c. extended temperature crystals are available at a much higher cost.
? 2004 microchip technology inc. preliminary ds39625b-page 421 pic18f2585/2680/4585/4680 supply current (i dd ) (2,3) pic18lfx585/x680 18 36 a -40c v dd = 2.0v f osc = 31 khz ( rc_run mode, internal oscillator source) 20 40 a+25c 25 50 a+85c pic18lfx585/x680 50 100 a -40c v dd = 3.0v 50 100 a+25c 50 100 a+85c all devices 120 240 a -40c v dd = 5.0v 100 200 a+25c 100 200 a+85c pic18lfx585/x680 450 900 a -40c v dd = 2.0v f osc = 1 mhz ( rc_run mode, internal oscillator source) 0.5 1.0 ma +25c 0.55 1.1 ma +85c pic18lfx585/x680 0.8 1.6 ma -40c v dd = 3.0v 0.8 1.6 ma +25c 0.8 1.6 ma +85c all devices 1.5 3.0 ma -40c v dd = 5.0v 1.5 3.0 ma +25c 1.5 3.0 ma +85c pic18lfx585/x680 1.2 2.2 ma -40c v dd = 2.0v f osc = 4 mhz ( rc_run mode, internal oscillator source) 1.2 2.5 ma +25c 1.5 3.0 ma +85c pic18lfx585/x680 2.1 4.0 ma -40c v dd = 3.0v 2.1 4.0 ma +25c 2.1 4.0 ma +85c all devices 4.0 8.0 ma -40c v dd = 5.0v 4.0 8.0 ma +25c 4.0 8.0 ma +85c 27.2 dc characteristics: power-down and supply current pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) (continued) pic18lf2585/2680/4585/4680 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f2585/2680/4585/4680 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? . 4: standard low-cost 32 khz crystals have an operating temper ature range of -10c to + 70c. extended temperature crystals are available at a much higher cost.
pic18f2585/2680/4585/4680 ds39625b-page 422 preliminary ? 2004 microchip technology inc. supply current (i dd ) (2,3) pic18lfx585/x680 5 10 a -40c v dd = 2.0v f osc = 31 khz ( rc_idle mode, internal oscillator source) 510 a+25c 7.2 15 a+85c pic18lfx585/x680 8 16 a -40c v dd = 3.0v 10 20 a+25c 12 24 a+85c all devices 16 32 a -40c v dd = 5.0v 18 36 a+25c 25 50 a+85c pic18lfx585/x680 230 450 a -40c v dd = 2.0v f osc = 1 mhz ( rc_idle mode, internal oscillator source) 250 500 a+25c 300 600 a+85c pic18lfx585/x680 350 700 a -40c v dd = 3.0v 400 800 a+25c 450 900 a+85c all devices 0.7 1.4 ma -40c v dd = 5.0v 0.7 1.4 ma +25c 0.8 1.6 ma +85c pic18lfx585/x680 0.6 1.2 ma -40c v dd = 2.0v f osc = 4 mhz ( rc_idle mode, internal oscillator source) 0.65 1.4 ma +25c 0.7 1.5 ma +85c pic18lfx585/x680 0.9 1.8 ma -40c v dd = 3.0v 0.95 1.9 ma +25c 1.1 2.2 ma +85c all devices 1.8 3.6 ma -40c v dd = 5.0v 1.8 3.6 ma +25c 1.9 4.0 ma +85c 27.2 dc characteristics: power-down and supply current pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) (continued) pic18lf2585/2680/4585/4680 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f2585/2680/4585/4680 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? . 4: standard low-cost 32 khz crystals have an operating temper ature range of -10c to + 70c. extended temperature crystals are available at a much higher cost.
? 2004 microchip technology inc. preliminary ds39625b-page 423 pic18f2585/2680/4585/4680 supply current (i dd ) (2,3) pic18lfx585/x680 380 780 a -40c v dd = 2.0v f osc = 1 mh z ( pri_run , ec oscillator) 400 800 a+25c 400 800 a+85c pic18lfx585/x680 0.73 1.5 ma -40c v dd = 3.0v 0.7 1.4 ma +25c 0.75 1.5 ma +85c all devices 1.5 3.0 ma -40c v dd = 5.0v 1.5 3.0 ma +25c 1.5 3.0 ma +85c pic18lfx585/x680 1.2 2.4 ma -40c v dd = 2.0v f osc = 4 mhz ( pri_run , ec oscillator) 1.2 2.4 ma +25c 1.3 2.6 ma +85c pic18lfx585/x680 2.0 4.0 ma -40c v dd = 3.0v 2.0 4.0 ma +25c 2.0 4.0 ma +85c all devices 4.0 8.0 ma -40c v dd = 5.0v 4.0 8.0 ma +25c 4.0 8.0 ma +85c all devices 27 54 ma -40c v dd = 4.2v f osc = 40 mh z ( pri_run , ec oscillator) 28 55 ma +25c 30 60 ma +85c all devices 33 70 ma -40c v dd = 5.0v 33 70 ma +25c 35 75 ma +85c 27.2 dc characteristics: power-down and supply current pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) (continued) pic18lf2585/2680/4585/4680 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f2585/2680/4585/4680 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? . 4: standard low-cost 32 khz crystals have an operating temper ature range of -10c to + 70c. extended temperature crystals are available at a much higher cost.
pic18f2585/2680/4585/4680 ds39625b-page 424 preliminary ? 2004 microchip technology inc. supply current (i dd ) (2,3) all devices 7.5 16 ma -40c v dd = 4.2v f osc = 4 mh z ( pri_run hs+pll ) 7.4 15 ma +25c 7.3 14 ma +85c all devices 10 21 ma -40c v dd = 5.0v f osc = 4 mh z ( pri_run hs+pll ) 10 20 ma +25c 9.7 19 ma +85c all devices 17 35 ma -40c v dd = 4.2v f osc = 10 mh z ( pri_run hs+pll ) 17 35 ma +25c 17 35 ma +85c all devices 23 40 ma -40c v dd = 5.0v f osc = 10 mh z ( pri_run hs+pll ) 23 40 ma +25c 23 40 ma +85c 27.2 dc characteristics: power-down and supply current pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) (continued) pic18lf2585/2680/4585/4680 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f2585/2680/4585/4680 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? . 4: standard low-cost 32 khz crystals have an operating temper ature range of -10c to + 70c. extended temperature crystals are available at a much higher cost.
? 2004 microchip technology inc. preliminary ds39625b-page 425 pic18f2585/2680/4585/4680 supply current (i dd ) (2,3) pic18lfx585/x680 130 260 a -40c v dd = 2.0v f osc = 1 mhz ( pri_idle mode, ec oscillator) 150 300 a+25c 150 300 a+85c pic18lfx585/x680 200 400 a -40c v dd = 3.0v 250 500 a+25c 250 500 a+85c all devices 400 800 a -40c v dd = 5.0v 400 800 a+25c 410 820 a+85c pic18lfx585/x680 0.5 1.0 ma -40c v dd = 2.0v f osc = 4 mhz ( pri_idle mode, ec oscillator) 0.55 1.1 ma +25c 0.55 1.1 ma +85c pic18lfx585/x680 0.8 1.6 ma -40c v dd = 3.0v 0.85 1.9 ma +25c 0.9 1.9 ma +85c all devices 1.5 3.0 ma -40c v dd = 5.0v 1.6 3.2 ma +25c 1.7 3.4 ma +85c all devices 12 24 ma -40c v dd = 4.2 v f osc = 40 mhz ( pri_idle mode, ec oscillator) 13 26 ma +25c 14 28 ma +85c all devices 15.5 32 ma -40c v dd = 5.0v 16 32 ma +25c 17 35 ma +85c 27.2 dc characteristics: power-down and supply current pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) (continued) pic18lf2585/2680/4585/4680 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f2585/2680/4585/4680 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? . 4: standard low-cost 32 khz crystals have an operating temper ature range of -10c to + 70c. extended temperature crystals are available at a much higher cost.
pic18f2585/2680/4585/4680 ds39625b-page 426 preliminary ? 2004 microchip technology inc. supply current (i dd ) (2,3) pic18lfx585/x680 23 46 a -10c v dd = 2.0v f osc = 32 khz (4) ( sec_run mode, timer1 as clock) 24 48 a+25c 26 52 a+70c pic18lfx585/x680 52 104 a -10c v dd = 3.0v 45 90 a+25c 43 86 a+70c all devices 120 240 a -10c v dd = 5.0v 100 200 a+25c 90 180 a+70c pic18lfx585/x680 9 18 a -10c v dd = 2.0v f osc = 32 khz (4) ( sec_idle mode, timer1 as clock) 11 22 a+25c 14 28 a+70c pic18lfx585/x680 12 24 a -10c v dd = 3.0v 13 26 a+25c 17 34 a+70c all devices 17 34 a -10c v dd = 5.0v 19 38 a+25c 26 52 a+70c 27.2 dc characteristics: power-down and supply current pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) (continued) pic18lf2585/2680/4585/4680 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f2585/2680/4585/4680 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? . 4: standard low-cost 32 khz crystals have an operating temper ature range of -10c to + 70c. extended temperature crystals are available at a much higher cost.
? 2004 microchip technology inc. preliminary ds39625b-page 427 pic18f2585/2680/4585/4680 module differential currents ( ? i wdt , ? i bor , ? i lvd , ? i oscb , ? i ad ) d022 ( ? i wdt ) watchdog timer 1.0 7.6 a -40c v dd = 2.0v 1.3 8 a+25c 1.4 8.4 a+85c 1.9 11.4 a -40c v dd = 3.0v 2.2 12 a+25c 2.4 12.6 a+85c 5.5 14.3 a -40c v dd = 5.0v 6.1 15 a+25c 6.5 15.8 a+85c d022a brown-out reset 37 75 a-40 c to +85 cv dd = 3.0v ( ? i bor )4792 a-40 c to +85 cv dd = 5.0v d022b high/low-voltage detect 22 47 a-40 c to +85 c v dd = 2.0v ( ? i lvd )2258 a-40 c to +85 cv dd = 3.0v 26 69 a-40 c to +85 cv dd = 5.0v d025 timer1 oscillator 48 a-10 c v dd = 2.0v 32 khz on timer1 (4) ( ? i oscb )48 a+25 c 48 a+70 c 4.2 8.2 a-10 c v dd = 3.0v 32 khz on timer1 (4) 4.2 8.2 a+25 c 4.2 8.2 a+70 c 5.0 10 a-10 c v dd = 5.0v 32 khz on timer1 (4) 5.0 10 a+25 c 5.0 10 a+70 c d026 ( ? i ad ) a/d converter 0.3 2 a-40 c to +85 c v dd = 2.0v a/d on, not converting, 1.6 s t ad 6.4 s 0.3 2 a-40 c to +85 c v dd = 3.0v 0.3 2 a-40 c to +85 c v dd = 5.0v 27.2 dc characteristics: power-down and supply current pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) (continued) pic18lf2585/2680/4585/4680 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f2585/2680/4585/4680 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-ra il; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be estimated by the formula ir = v dd /2r ext (ma) with r ext in k ? . 4: standard low-cost 32 khz crystals have an operating temper ature range of -10c to + 70c. extended temperature crystals are available at a much higher cost.
pic18f2585/2680/4585/4680 ds39625b-page 428 preliminary ? 2004 microchip technology inc. 27.3 dc characteristics: pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min max units conditions v il input low voltage i/o ports: d030 with ttl buffer v ss 0.15 v dd vv dd < 4.5v d030a ? 0.8 v 4.5v v dd 5.5v d031 with schmitt trigger buffer rc3 and rc4 v ss v ss 0.2 v dd 0.3 v dd v v d032 mclr v ss 0.2 v dd v d032a osc1 and t1osi v ss 0.3 v dd v lp, xt, hs, hspll modes (1) d033 osc1 v ss 0.2 v dd vec mode (1) v ih input high voltage i/o ports: d040 with ttl buffer 0.25 v dd + 0.8v v dd vv dd < 4.5v d040a 2.0 v dd v4.5v v dd 5.5v d041 with schmitt trigger buffer rc3 and rc4 0.8 v dd 0.7 v dd v dd v dd v v d042 mclr 0.8 v dd v dd v d042a osc1 and t1osi 0.7 v dd v dd v lp, xt, hs, hspll modes (1) d043 osc1 0.8 v dd v dd vec mode (1) i il input leakage current (2,3) d060 i/o ports ? 1 av ss v pin v dd , pin at high-impedance d061 mclr ? 5 avss v pin v dd d063 osc1 ? 5 avss v pin v dd i pu weak pull-up current d070 i purb portb weak pull-up current 50 400 av dd = 5v, v pin = v ss note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the picmicro ? device be driven with an external clock while in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin. 4: parameter is characterized but not tested.
? 2004 microchip technology inc. preliminary ds39625b-page 429 pic18f2585/2680/4585/4680 v ol output low voltage d080 i/o ports ? 0.6 v i ol = 8.5 ma, v dd = 4.5v, -40 c to +85 c d083 osc2/clko (rc, rcio, ec, ecio modes) ?0.6vi ol = 1.6 ma, v dd = 4.5v, -40 c to +85 c v oh output high voltage (3) d090 i/o ports v dd ? 0.7 ? v i oh = -3.0 ma, v dd = 4.5v, -40 c to +85 c d092 osc2/clko (rc, rcio, ec, ecio modes) v dd ? 0.7 ? v i oh = -1.3 ma, v dd = 4.5v, -40 c to +85 c capacitive loading specs on output pins d100 (4) c osc2 osc2 pin ? 15 pf in xt, hs and lp modes when external clock is used to drive osc1 d101 c io all i/o pins and osc2 (in rc mode) ? 50 pf to meet the ac timing specifications d102 c b scl, sda ? 400 pf i 2 c? specification 27.3 dc characteristics: pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min max units conditions note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the picmicro ? device be driven with an external clock while in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin. 4: parameter is characterized but not tested.
pic18f2585/2680/4585/4680 ds39625b-page 430 preliminary ? 2004 microchip technology inc. table 27-1: memory programming requirements dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ? max units conditions internal program memory programming specifications (1) d110 v pp voltage on mclr /v pp /re3 pin 9.00 ? 13.25 v (note 3) d113 i ddp supply current during programming ??10ma data eeprom memory d120 e d byte endurance 100k 1m ? e/w -40 c to +85 c d121 v drw v dd for read/write v min ? 5.5 v using eecon to read/write v min = minimum operating voltage d122 t dew erase/write cycle time ? 4 ? ms d123 t retd characteristic retention 40 ? ? year provided no other specifications are violated d124 t ref number of total erase/write cycles before refresh (2) 1m 10m ? e/w -40c to +85c program flash memory d130 e p cell endurance 10k 100k ? e/w -40 c to +85 c d131 v pr v dd for read v min ?5.5vv min = minimum operating voltage d132 v ie v dd for block erase 4.5 ? 5.5 v using icsp? port d132a v iw v dd for externally timed erase or write 4.5 ? 5.5 v using icsp port d132b v pew v dd for self-timed write v min ?5.5vv min = minimum operating voltage d133 t ie icsp block erase cycle time ? 4 ? ms v dd > 4.5v d133a t iw icsp erase or write cycle time (externally timed) 1??msv dd > 4.5v d133a t iw self-timed write cycle time ? 2 ? ms d134 t retd characteristic retention 40 100 ? year provided no other specifications are violated ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: these specifications are for programming the on-chip program memory through the use of table write instructions. 2: refer to section 7.8 ?using the data eeprom? for a more detailed discussion on data eeprom endurance. 3: required only if single-supply programming is disabled.
? 2004 microchip technology inc. preliminary ds39625b-page 431 pic18f2585/2680/4585/4680 table 27-2: comparator specifications table 27-3: voltage reference specifications operating conditions: 3.0v < v dd < 5.5v, -40c < t a < +85c (unless otherwise stated). param no. sym characteristics min typ max units comments d300 v ioff input offset voltage ? 5.0 10 mv d301 v icm input common mode voltage* 0 ? v dd ? 1.5 v d302 cmrr common mode rejection ratio* 55 ? ? db 300 t resp response time (1)* ? 150 400 ns pic18 f xxxx 300a ? 150 600 ns pic18l f xxxx, v dd = 2.0v 301 t mc 2 ov comparator mode change to output valid* ?? 10 s * these parameters are characterized but not tested. note 1: response time measured with one comparator input at (v dd ? 1.5)/2 while the other input transitions from v ss to v dd . operating conditions: 3.0v < v dd < 5.5v, -40c < t a < +85c (unless otherwise stated). param no. sym characteristics min typ max units comments d310 v res resolution v dd /24 ? v dd /32 lsb d311 vr aa absolute accuracy ? ? ? ? 1/4 1/2 lsb lsb low range (cvrr = 1 ) high range (cvrr = 0 ) d312 vr ur unit resistor value (r)* ? 2k ? ? 310 t set settling time (1) * ? ? 10 s * these parameters are characterized but not tested. note 1: settling time measured while cvrr = 1 and cvr3:cvr0 transitions from ? 0000 ? to ? 1111 ?.
pic18f2585/2680/4585/4680 ds39625b-page 432 preliminary ? 2004 microchip technology inc. figure 27-3: high/low-voltage detect characteristics table 27-4: high/low-voltage detect characteristics v lvd hlvdif v dd (hlvdif set by hardware) (hlvdif can be cleared in software) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min typ? max units conditions d420 hlvd voltage on v dd transition high to low lvv = 0000 2.12 2.17 2.22 v lvv = 0001 2.18 2.23 2.28 v lvv = 0010 2.31 2.36 2.42 v lvv = 0011 2.38 2.44 2.49 v lvv = 0100 2.54 2.60 2.66 v lvv = 0101 2.72 2.79 2.85 v lvv = 0110 2.82 2.89 2.95 v lvv = 0111 3.05 3.12 3.19 v lvv = 1000 3.31 3.39 3.47 v lvv = 1001 3.46 3.55 3.63 v lvv = 1010 3.63 3.71 3.80 v lvv = 1011 3.81 3.90 3.99 v lvv = 1100 4.01 4.11 4.20 v lvv = 1101 4.23 4.33 4.43 v lvv = 1110 4.48 4.59 4.69 v ? production tested at t amb = 25c. specifications over temperature limits ensured by characterization.
? 2004 microchip technology inc. preliminary ds39625b-page 433 pic18f2585/2680/4585/4680 27.4 ac (timing) characteristics 27.4.1 timing parameter symbology the timing parameter symbols have been created using one of the following formats: 1. tpps2pps 3. t cc : st (i 2 c specifications only) 2. tpps 4. ts (i 2 c specifications only) t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc osc1 ck clko rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t13cki mc mclr wr wr uppercase letters and their meanings: s f fall p period hhigh rrise i invalid (high-impedance) v valid l low z high-impedance i 2 c only aa output access high high buf bus free low low t cc : st (i 2 c specifications only) cc hd hold su setup st dat data input hold sto stop condition sta start condition
pic18f2585/2680/4585/4680 ds39625b-page 434 preliminary ? 2004 microchip technology inc. 27.4.2 timing conditions the temperature and voltages specified in table 27-5 apply to all timing specifications unless otherwise noted. figure 27-4 specifies the load conditions for the timing specifications. table 27-5: temperature and voltage specifications ? ac figure 27-4: load conditions for devi ce timing specifications note: because of space limitations, the generic terms ?pic18fxxxx? and ?pic18lfxxxx? are used throughout this section to refer to the pic18f2585/2680/4585/4680 and pic18lf2585/2680/4585/4680 families of devices specifically and only those devices. ac characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial operating voltage v dd range as described in dc spec section 27.1 and section 27.3 . lf parts operate for industrial temperatures only. v dd /2 c l r l pin pin v ss v ss c l r l = 464 ? c l = 50 pf for all pins except osc2/clko and including d and e outputs as ports load condition 1 load condition 2
? 2004 microchip technology inc. preliminary ds39625b-page 435 pic18f2585/2680/4585/4680 27.4.3 timing diagrams and specifications figure 27-5: external clock timing (all modes except pll) table 27-6: external clock timing requirements osc1 clko q4 q1 q2 q3 q4 q1 1 2 3 3 4 4 param. no. symbol characteristic min max units conditions 1a f osc external clki frequency (1) dc 40 mhz ec, ecio oscillator mode oscillator frequency (1) dc 4 mhz rc oscillator mode 0.1 4 mhz xt oscillator mode 4 25 mhz hs oscillator mode 4 10 mhz hs + pll oscillator mode 5 200 khz lp oscillator mode 1t osc external clki period (1) 25 ? ns ec, ecio oscillator mode oscillator period (1) 250 ? ns rc oscillator mode 250 10,000 ns xt oscillator mode 40 250 ns hs oscillator mode 100 250 ns hs + pll oscillator mode 25 ? s lp oscillator mode 2t cy instruction cycle time (1) 100 ? ns t cy = 4/f osc 3t os l, t os h external clock in (osc1) high or low time 30 ? ns xt oscillator mode 2.5 ? s lp oscillator mode 10 ? ns hs oscillator mode 4t os r, t os f external clock in (osc1) rise or fall time ? 20 ns xt oscillator mode ? 50 ns lp oscillator mode ? 7.5 ns hs oscillator mode note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period for all configurations except pll. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min.? values with an external clock applied to the osc1/clki pin. when an external clock input is used, the ?max.? cycle time limit is ?dc? (no clock) for all devices.
pic18f2585/2680/4585/4680 ds39625b-page 436 preliminary ? 2004 microchip technology inc. table 27-7: pll clock timing specifications (v dd = 4.2v to 5.5v) table 27-8: ac characteristics: internal rc accuracy pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) param no. sym characteristic min typ? max units conditions f10 f osc oscillator frequency range 4 ? 10 mhz hs mode only f11 f sys on-chip vco system frequency 16 ? 40 mhz hs mode only f12 t rc pll start-up time (lock time) ? ? 2 ms f13 ? clk clko stability (jitter) -2 ? +2 % ? data in ?typ? column is at 5v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. pic18lf2585/2680/4585/4680 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f2585/2680/4585/4680 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device min typ max units conditions intosc accuracy @ freq = 8 mhz, 4 mhz, 2 mhz, 1 mhz, 500 khz, 250 khz, 125 khz (1) pic18lfx585/x680 -2 +/-1 2 % +25c v dd = 2.7-3.3v -5 ? 5 % -10c to +85c v dd = 2.7-3.3v -10 +/-1 10 % -40c to +85c v dd = 2.7-3.3v pic18fx585/x680 -2 +/-1 2 % +25c v dd = 4.5-5.5v -5 ? 5 % -10c to +85c v dd = 4.5-5.5v -10 +/-1 10 % -40c to +85c v dd = 4.5-5.5v intrc accuracy @ freq = 31 khz (2) pic18lfx585/x680 26.562 ? 35.938 khz -40c to +85c v dd = 2.7-3.3v pic18fx585/x680 26.562 ? 35.938 khz -40c to +85c v dd = 4.5-5.5v intrc stability (3) f7 pic18lfx585/x680 tbd 1 tbd % +25c v dd = 2.0v f8 tbd 1 tbd % +25c v dd = 3.0v f9 all devices tbd 1 tbd % +25c v dd = 5.0v legend: shading of rows is to assist in readability of the table. note 1: frequency calibrated at 25c. osctune register can be used to compensate for temperature drift. 2: intrc frequency after calibration. 3: change of intrc frequency as v dd changes.
? 2004 microchip technology inc. preliminary ds39625b-page 437 pic18f2585/2680/4585/4680 figure 27-6: clko and i/o timing table 27-9: clko and i/o timing requirements note: refer to figure 27-4 for load conditions. osc1 clko i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 19 18 15 11 12 16 old value new value param no. symbol characteristic min typ max units conditions 10 t os h2 ck losc1 to clko ? 75 200 ns (note 1) 11 t os h2 ck hosc1 to clko ? 75 200 ns (note 1) 12 t ck r clko rise time ? 35 100 ns (note 1) 13 t ck f clko fall time ? 35 100 ns (note 1) 14 t ck l2 io vclko to port out valid ? ? 0.5 t cy + 20 ns (note 1) 15 t io v2 ck h port in valid before clko 0.25 t cy + 25 ? ? ns (note 1) 16 t ck h2 io i port in hold after clko 0??ns (note 1) 17 t os h2 io vosc1 (q1 cycle) to port out valid ? 50 150 ns 18 t os h2 io iosc1 (q2 cycle) to port input invalid (i/o in hold time) pic18 f xxxx 100 ? ? ns 18a pic18 lf xxxx 200 ? ? ns v dd = 2.0v 19 t io v2 os h port input valid to osc1 (i/o in setup time) 0??ns 20 t io r port output rise time pic18 f xxxx ? 10 25 ns 20a pic18 lf xxxx ? ? 60 ns v dd = 2.0v 21 t io f port output fall time pic18 f xxxx ? 10 25 ns 21a pic18 lf xxxx ? ? 60 ns v dd = 2.0v 22? t inp int pin high or low time t cy ??ns 23? t rbp rb7:rb4 change int high or low time t cy ??ns 24? t rcp rc7:rc4 change int high or low time 20 ns ? these parameters are asynchronous events not related to any internal clock edges. note 1: measurements are taken in rc mode, where clko output is 4 x t osc .
pic18f2585/2680/4585/4680 ds39625b-page 438 preliminary ? 2004 microchip technology inc. figure 27-7: reset, watchdog timer, oscillator start-up timer and power-up timer timing figure 27-8: brown-out reset timing table 27-10: reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements param. no. sym characteristic min typ max units conditions 30 t mc lmclr pulse width (low) 2 ? ? s 31 t wdt watchdog timer time-out period (no postscaler) ?4.00tbd ms 32 t ost oscillation start-up timer period 1024 t osc ? 1024 t osc ?t osc = osc1 period 33 t pwrt power-up timer period ? 65.5 tbd ms 34 tioz i/o high-impedance from mclr low or watchdog timer reset ?2? s 35 t bor brown-out reset pulse width 200 ? ? sv dd b vdd (see d005) 36 t ivrst time for internal reference voltage to become stable ?2050 s 37 t lvd high/low-voltage detect pulse width 200 ? ? sv dd v lvd 38 t csd cpu start-up time 5 ? 10 s 39 t iobst time for intosc to stabilize ? 1 ? ms legend: tbd = to be determined v dd mclr internal por pwrt time-out osc time-out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 note: refer to figure 27-4 for load conditions. v dd bv dd 35 v bgap = 1.2v v irvst enable internal internal reference 36 reference voltage voltage stable
? 2004 microchip technology inc. preliminary ds39625b-page 439 pic18f2585/2680/4585/4680 figure 27-9: timer0 and timer1 external clock timings table 27-11: timer0 and timer1 external clock requirements note: refer to figure 27-4 for load conditions. 46 47 45 48 41 42 40 t0cki t1oso/t13cki tmr0 or tmr1 param no. sym characteristic min max units conditions 40 t t 0h t0cki high pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 41 t t 0l t0cki low pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 42 t t 0p t0cki period no prescaler t cy + 10 ? ns with prescaler greater of: 20 ns or (t cy + 40)/n ? ns n = prescale value (1, 2, 4,..., 256) 45 t t 1h t13cki high time synchronous, no prescaler 0.5 t cy + 20 ? ns synchronous, with prescaler pic18 f xxxx 10 ? ns pic18 lf xxxx 25 ? ns v dd = 2.0v asynchronous pic18 f xxxx 30 ? ns pic18 lf xxxx 50 ? ns v dd = 2.0v 46 t t 1l t13cki low time synchronous, no prescaler 0.5 t cy + 5 ? ns synchronous, with prescaler pic18 f xxxx 10 ? ns pic18 lf xxxx 25 ? ns v dd = 2.0v asynchronous pic18 f xxxx 30 ? ns pic18 lf xxxx 50 ? ns v dd = 2.0v 47 t t 1p t13cki input period synchronous greater of: 20 ns or (t cy + 40)/n ? ns n = prescale value (1, 2, 4, 8) asynchronous 60 ? ns f t 1 t13cki oscillator input frequency range dc 50 khz 48 t cke 2 tmr i delay from external t13cki clock edge to timer increment 2 t osc 7 t osc ?
pic18f2585/2680/4585/4680 ds39625b-page 440 preliminary ? 2004 microchip technology inc. figure 27-10: capture/compare/pwm timings (all ccp modules) table 27-12: capture/compare/pwm requirements (all ccp modules) note: refer to figure 27-4 for load conditions. ccpx (capture mode) 50 51 52 ccpx 53 54 (compare or pwm mode) param no. sym characteristic min max units conditions 50 t cc l ccpx input low time no prescaler 0.5 t cy + 20 ? ns with prescaler pic18 f xxxx 10 ? ns pic18 lf xxxx 20 ? ns v dd = 2.0v 51 t cc h ccpx input high time no prescaler 0.5 t cy + 20 ? ns with prescaler pic18 f xxxx 10 ? ns pic18 lf xxxx 20 ? ns v dd = 2.0v 52 t cc p ccpx input period 3 t cy + 40 n ?nsn = prescale value (1,4 or 16) 53 t cc r ccpx output fall time pic18 f xxxx ? 25 ns pic18 lf xxxx ? 45 ns v dd = 2.0v 54 t cc f ccpx output fall time pic18 f xxxx ? 25 ns pic18 lf xxxx ? 45 ns v dd = 2.0v
? 2004 microchip technology inc. preliminary ds39625b-page 441 pic18f2585/2680/4585/4680 figure 27-11: parallel slave port timing (pic18f4585/4680) table 27-13: parallel slave port requirements (pic18f4585/4680) note: refer to figure 27-4 for load conditions. re2/cs re0/rd re1/wr rd7:rd0 62 63 64 65 param. no. symbol characteristic min max units conditions 62 t dt v2 wr h data in valid before wr or cs (setup time) 20 ? ns 63 t wr h2 dt iwr or cs to data?in invalid (hold time) pic18 f xxxx 20 ? ns pic18 lf xxxx 35 ? ns v dd = 2.0v 64 t rd l2 dt vrd and cs to data?out valid ? 80 ns 65 t rd h2 dt ird or cs to data?out invalid 10 30 ns 66 t ibf inh inhibit of the ibf flag bit being cleared from wr or cs ?3 t cy
pic18f2585/2680/4585/4680 ds39625b-page 442 preliminary ? 2004 microchip technology inc. figure 27-12: example spi? master mode timing (cke = 0 ) table 27-14: example spi? mode requirements (master mode, cke = 0 ) ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 70 71 72 73 74 75, 76 78 79 80 79 78 msb lsb bit 6 - - - - - -1 msb in lsb in bit 6 - - - -1 note: refer to figure 27-4 for load conditions. param no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ss to sck or sck input t cy ?ns 71 t sc h sck input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sck input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73 t di v2 sc h, t di v2 sc l setup time of sdi data input to sck edge 100 ? ns 73a t b 2 b last clock edge of byte 1 to the 1st clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdi data input to sck edge 100 ? ns 75 t do r sdo data output rise time pic18 f xxxx ? 25 ns pic18 lf xxxx ? 45 ns v dd = 2.0v 76 t do f sdo data output fall time ? 25 ns 78 t sc r sck output rise time (master mode) pic18 f xxxx ? 25 ns pic18 lf xxxx ? 45 ns v dd = 2.0v 79 t sc f sck output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdo data output valid after sck edge pic18 f xxxx ? 50 ns pic18 lf xxxx ? 100 ns v dd = 2.0v note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used.
? 2004 microchip technology inc. preliminary ds39625b-page 443 pic18f2585/2680/4585/4680 figure 27-13: example spi? master mode timing (cke = 1 ) table 27-15: example spi? mode requirements (master mode, cke = 1 ) ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 81 71 72 74 75, 76 78 80 msb 79 73 msb in bit 6 - - - - - -1 lsb in bit 6 - - - -1 lsb note: refer to figure 27-4 for load conditions. param. no. symbol characteristic min max units conditions 71 t sc h sck input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sck input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73 t di v2 sc h, t di v2 sc l setup time of sdi data input to sck edge 100 ? ns 73a t b 2 b last clock edge of byte 1 to the 1st clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdi data input to sck edge 100 ? ns 75 t do r sdo data output rise time pic18 f xxxx ? 25 ns pic18 lf xxxx 45 ns v dd = 2.0v 76 t do f sdo data output fall time ? 25 ns 78 t sc r sck output rise time (master mode) pic18 f xxxx ? 25 ns pic18 lf xxxx 45 ns v dd = 2.0v 79 t sc f sck output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdo data output valid after sck edge pic18 f xxxx ? 50 ns pic18 lf xxxx 100 ns v dd = 2.0v 81 t do v2 sc h, t do v2 sc l sdo data output setup to sck edge t cy ?ns note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used.
pic18f2585/2680/4585/4680 ds39625b-page 444 preliminary ? 2004 microchip technology inc. figure 27-14: example spi? slave mode timing (cke = 0 ) table 27-16: example spi? mode requirements (slave mode timing, cke = 0 ) param no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ss to sck or sck input t cy ?ns 71 t sc h sck input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sck input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73 t di v2 sc h, t di v2 sc l setup time of sdi data input to sck edge 100 ? ns 73a t b 2 b last clock edge of byte1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdi data input to sck edge 100 ? ns 75 t do r sdo data output rise time pic18 f xxxx ? 25 ns pic18 lf xxxx 45 ns v dd = 2.0v 76 t do f sdo data output fall time ? 25 ns 77 t ss h2 do zss to sdo output high-impedance 10 50 ns 78 t sc r sck output rise time (master mode) pic18 f xxxx ? 25 ns pic18 lf xxxx 45 ns v dd = 2.0v 79 t sc f sck output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdo data output valid after sck edge pic18 f xxxx ? 50 ns pic18 lf xxxx 100 ns v dd = 2.0v 83 tsch2ssh, ts c l 2 s s h ss after sck edge 1.5 t cy + 40 ? ns note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used. ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 70 71 72 73 74 75, 76 77 78 79 80 79 78 sdi msb lsb bit 6 - - - - - -1 msb in bit 6 - - - -1 lsb in 83 note: refer to figure 27-4 for load conditions.
? 2004 microchip technology inc. preliminary ds39625b-page 445 pic18f2585/2680/4585/4680 figure 27-15: example spi? slave mode timing (cke = 1 ) table 27-17: example spi? slave mode requirements (cke = 1 ) param no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ss to sck or sck input t cy ?ns 71 t sc h sck input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sck input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73a t b 2 b last clock edge of byte 1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdi data input to sck edge 100 ? ns 75 t do r sdo data output rise time pic18 f xxxx ? 25 ns pic18 lf xxxx 45 ns v dd = 2.0v 76 t do f sdo data output fall time ? 25 ns 77 t ss h2 do zss to sdo output high-impedance 10 50 ns 78 t sc r sck output rise time (master mode) pic18 f xxxx ? 25 ns pic18 lf xxxx ? 45 ns v dd = 2.0v 79 t sc f sck output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdo data output valid after sck edge pic18 f xxxx ? 50 ns pic18 lf xxxx ? 100 ns v dd = 2.0v 82 t ss l2 do v sdo data output valid after ss edge pic18 f xxxx ? 50 ns pic18 lf xxxx ? 100 ns v dd = 2.0v 83 t sc h2 ss h, t sc l2 ss h ss after sck edge 1.5 t cy + 40 ? ns note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used. ss sck (ckp = 0 ) sck (ckp = 1 ) sdo sdi 70 71 72 82 sdi 74 75, 76 msb bit 6 - - - - - -1 lsb 77 msb in bit 6 - - - -1 lsb in 80 83 note: refer to figure 27-4 for load conditions.
pic18f2585/2680/4585/4680 ds39625b-page 446 preliminary ? 2004 microchip technology inc. figure 27-16: i 2 c? bus start/stop bits timing table 27-18: i 2 c? bus start/stop bits requirements (slave mode) figure 27-17: i 2 c? bus data timing note: refer to figure 27-4 for load conditions. 91 92 93 scl sda start condition stop condition 90 param. no. symbol characteristic min max units conditions 90 t su : sta start condition 100 khz mode 4700 ? ns only relevant for repeated start condition setup time 400 khz mode 600 ? 91 t hd : sta start condition 100 khz mode 4000 ? ns after this period, the first clock pulse is generated hold time 400 khz mode 600 ? 92 t su : sto stop condition 100 khz mode 4700 ? ns setup time 400 khz mode 600 ? 93 t hd : sto stop condition 100 khz mode 4000 ? ns hold time 400 khz mode 600 ? note: refer to figure 27-4 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 scl sda in sda out
? 2004 microchip technology inc. preliminary ds39625b-page 447 pic18f2585/2680/4585/4680 table 27-19: i 2 c? bus data requirements (slave mode) param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 4.0 ? s pic18fxxxx must operate at a minimum of 1.5 mhz 400 khz mode 0.6 ? s pic18fxxxx must operate at a minimum of 10 mhz ssp module 1.5 t cy ? 101 t low clock low time 100 khz mode 4.7 ? s pic18fxxxx must operate at a minimum of 1.5 mhz 400 khz mode 1.3 ? s pic18fxxxx must operate at a minimum of 10 mhz ssp module 1.5 t cy ? 102 t r sda and scl rise time 100 khz mode ? 1000 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 103 t f sda and scl fall time 100 khz mode ? 300 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 90 t su : sta start condition setup time 100 khz mode 4.7 ? s only relevant for repeated start condition 400 khz mode 0.6 ? s 91 t hd : sta start condition hold time 100 khz mode 4.0 ? s after this period, the first clock pulse is generated 400 khz mode 0.6 ? s 106 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 s 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 92 t su : sto stop condition setup time 100 khz mode 4.7 ? s 400 khz mode 0.6 ? s 109 t aa output valid from clock 100 khz mode ? 3500 ns (note 1) 400 khz mode ? ? ns 110 t buf bus free time 100 khz mode 4.7 ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? s d102 c b bus capacitive loading ? 400 pf note 1: as a transmitter, the device must provide this internal minimum delay time to bridge the undefined region (min. 300 ns) of the falling edge of scl to avoid unintended generation of start or stop conditions. 2: a fast mode i 2 c? bus device can be used in a standard mode i 2 c bus system but the requirement, t su : dat 250 ns, must then be met. this will automatically be the case if the device does not stretch the low period of the scl signal. if such a device does stretch the low period of the scl signal, it must out- put the next data bit to the sda line, t r max. + t su : dat = 1000 + 250 = 1250 ns (according to the standard mode i 2 c bus specification), before the scl line is released.
pic18f2585/2680/4585/4680 ds39625b-page 448 preliminary ? 2004 microchip technology inc. figure 27-18: master ssp i 2 c? bus start/stop bits timing waveforms table 27-20: master ssp i 2 c? bus start/stop bits requirements figure 27-19: master ssp i 2 c? bus data timing note: refer to figure 27-4 for load conditions. 91 93 scl sda start condition stop condition 90 92 param. no. symbol characteristic min max units conditions 90 t su : sta start condition 100 khz mode 2(t osc )(brg + 1) ? ns only relevant for repeated start condition setup time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 91 t hd : sta start condition 100 khz mode 2(t osc )(brg + 1) ? ns after this period, the first clock pulse is generated hold time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 92 t su : sto stop condition 100 khz mode 2(t osc )(brg + 1) ? ns setup time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 93 t hd : sto stop condition 100 khz mode 2(t osc )(brg + 1) ? ns hold time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? note 1: maximum pin capacitance = 10 pf for all i 2 c pins. note: refer to figure 27-4 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 scl sda in sda out
? 2004 microchip technology inc. preliminary ds39625b-page 449 pic18f2585/2680/4585/4680 table 27-21: master ssp i 2 c? bus data requirements param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 2(t osc )(brg + 1) ? ms 400 khz mode 2(t osc )(brg + 1) ? ms 1 mhz mode (1) 2(t osc )(brg + 1) ? ms 101 t low clock low time 100 khz mode 2(t osc )(brg + 1) ? ms 400 khz mode 2(t osc )(brg + 1) ? ms 1 mhz mode (1) 2(t osc )(brg + 1) ? ms 102 t r sda and scl rise time 100 khz mode ? 1000 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode (1) ? 300 ns 103 t f sda and scl fall time 100 khz mode ? 300 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode (1) ? 100 ns 90 t su : sta start condition setup time 100 khz mode 2(t osc )(brg + 1) ? ms only relevant for repeated start condition 400 khz mode 2(t osc )(brg + 1) ? ms 1 mhz mode (1) 2(t osc )(brg + 1) ? ms 91 t hd : sta start condition hold time 100 khz mode 2(t osc )(brg + 1) ? ms after this period, the first clock pulse is generated 400 khz mode 2(t osc )(brg + 1) ? ms 1 mhz mode (1) 2(t osc )(brg + 1) ? ms 106 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 ms 1 mhz mode (1) tbd ? ns 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 1 mhz mode (1) tbd ? ns 92 t su : sto stop condition setup time 100 khz mode 2(t osc )(brg + 1) ? ms 400 khz mode 2(t osc )(brg + 1) ? ms 1 mhz mode (1) 2(t osc )(brg + 1) ? ms 109 t aa output valid from clock 100 khz mode ? 3500 ns 400 khz mode ? 1000 ns 1 mhz mode (1) ??ns 110 t buf bus free time 100 khz mode 4.7 ? ms time the bus must be free before a new transmission can start 400 khz mode 1.3 ? ms 1 mhz mode (1) tbd ? ms d102 c b bus capacitive loading ? 400 pf legend: tbd = to be determined note 1: maximum pin capacitance = 10 pf for all i 2 c pins. 2: a fast mode i 2 c? bus device can be used in a standard mode i 2 c bus system, but parameter #107 250 ns must then be met. this will automatically be the case if the device does not stretch the low period of the scl signal. if such a device does stretch the low period of the scl signal, it must output the next data bit to the sda line, parameter #102 + parameter #107 = 1000 + 250 = 1250 ns (for 100 khz mode), before the scl line is released.
pic18f2585/2680/4585/4680 ds39625b-page 450 preliminary ? 2004 microchip technology inc. figure 27-20: eusart synchronous transmissi on (master/slave) timing table 27-22: eusart synchronous transmission requirements figure 27-21: eusart synchronous receive (master/slave) timing table 27-23: eusart synchronous receive requirements 121 121 120 122 rc6/tx/ck rc7/rx/dt pin pin note: refer to figure 27-4 for load conditions. param no. symbol characteristic min max units conditions 120 t ck h2 dt v sync xmit (master & slave) clock high to data out valid pic18 f xxxx ? 40 ns pic18 lf xxxx ? 100 ns v dd = 2.0v 121 t ckrf clock out rise time and fall time (master mode) pic18 f xxxx ? 20 ns pic18 lf xxxx ? 50 ns v dd = 2.0v 122 t dtrf data out rise time and fall time pic18 f xxxx ? 20 ns pic18 lf xxxx ? 50 ns v dd = 2.0v 125 126 rc6/tx/ck rc7/rx/dt pin pin note: refer to figure 27-4 for load conditions. param. no. symbol characteristic min max units conditions 125 t dt v2 ckl sync rcv (master & slave) data hold before ck (dt hold time) 10 ? ns 126 t ck l2 dtl data hold after ck (dt hold time) 15 ? ns
? 2004 microchip technology inc. preliminary ds39625b-page 451 pic18f2585/2680/4585/4680 table 27-24: a/d converter characteristics: pic18f2585/2680/4585/4680 (industrial) pic18lf2585/2680/4585/4680 (industrial) param no. sym characteristic min typ max units conditions a01 n r resolution ? ? 10 bit ? v ref 3.0v a03 e il integral linearity error ? ? <1 lsb ? v ref 3.0v a04 e dl differential linearity error ? ? <1 lsb ? v ref 3.0v a06 e off offset error ? ? <1 lsb ? v ref 3.0v a07 e gn gain error ? ? <1 lsb ? v ref 3.0v a10 ? monotonicity guaranteed (1) ? a20 ? v ref reference voltage range (v refh ? v refl ) 3?av dd ? av ss v for 10-bit resolution a21 v refh reference voltage high av ss + 3.0v ? av dd + 0.3v v for 10-bit resolution a22 v refl reference voltage low av ss ? 0.3v ? av dd ? 3.0v v for 10-bit resolution a25 v ain analog input voltage v refl ?v refh v a28 av dd analog supply voltage v dd ? 0.3 ? v dd + 0.3 v a29 av ss analog supply voltage v ss ? 0.3 ? v ss + 0.3 v a30 z ain recommended impedance of analog voltage source ??2.5k ? a40 i ad a/d conversion current (v dd ) pic18 f xxxx ? 180 ? a average current consumption when a/d is on (note 2) pic18 lf xxxx ? 90 ? av dd = 2.0v; average current consumption when a/d is on (note 2) a50 i ref v ref input current (note 3) ? ? ? ? 5 150 a a during v ain acquisition. during a/d conversion cycle. note 1: the a/d conversion result never decreases with an increase in the input voltage and has no missing codes. 2: when a/d is off, it will not consume any current other than minor leakage current. the power-down current spec includes any such leakage from the a/d module. 3: v refh current is from ra3/an3/v ref + pin or av dd , whichever is selected as the v refh source. v refl current is from ra2/an2/v ref - pin or av ss , whichever is selected as the v refl source.
pic18f2585/2680/4585/4680 ds39625b-page 452 preliminary ? 2004 microchip technology inc. figure 27-22: a/d conversion timing table 27-25: a/d conversion requirements 131 130 132 bsf adcon0, go q4 a/d clk (1) a/d data adres adif go sample old_data sampling stopped done new_data (note 2) 987 21 0 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 2: this is a minimal rc delay (typically 100 ns), which also disconnects the holding capacitor from the analog input. . . . . . . t cy param no. symbol characteristic min max units conditions 130 t ad a/d clock period pic18 f xxxx 1.6 20 (1) st osc based, v ref 3.0v pic18 lf xxxx 3.0 20 (1) sv dd = 2.0v; t osc based, v ref full range pic18 f xxxx 2.0 6.0 s a/d rc mode pic18 lf xxxx 3.0 9.0 sv dd = 2.0v; a/d rc mode 131 t cnv conversion time (not including acquisition time) (note 2) 11 12 t ad 132 t acq acquisition time (note 3) 15 10 ? ? s s -40 c to +85 c 0 c to +85 c 135 t swc switching time from convert sample ? (note 4) ? 136 t amp amplifier settling time (note 5) 1? s this may be used if the ?new? input voltage has not changed by more than 1 lsb (i.e., 5 mv @ 5.12v) from the last sampled voltage (as stated on c hold ). note 1: the time of the a/d clock period is dependent on the device frequency and the t ad clock divider. 2: adres register may be read on the following t cy cycle. 3: the time for the holding capacitor to acquire the ?new? input voltage when the voltage changes full scale after the conversion (av dd to av ss or av ss to av dd ). the source impedance ( r s ) on the input channels is 50 ? . 4: on the following cycle of the device clock. 5: see section 19.0 ?10-bit analog-to-digital converter (a/d) module? for minimum conditions when input voltage has changed more than 1 lsb.
? 2004 microchip technology inc. preliminary ds39625b-page 453 pic18f2585/2680/4585/4680 28.0 dc and ac characteristics graphs and tables graphs and tables are not available at this time.
pic18f2585/2680/4585/4680 ds39625b-page 454 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 455 pic18f2585/2680/4585/4680 29.0 packaging information 29.1 package marking information 28-lead pdip (skinny dip) xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example pic18f2680-i/sp 0410017 28-lead soic xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx yywwnnn example pic18f2680-e/so 0410017 40-lead pdip xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx yywwnnn example pic18f4585-i/p 0410017 legend: xx...x customer specific information* y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line thus limiting the number of available characters for customer specific information. * standard picmicro device marking consists of microchip part number, year code, week code, and traceability code. for picmicro device marking beyond this, certain price adders apply. please check with your microchip sales office. for qtp devices, any special marking adders are included in qtp price.
pic18f2585/2680/4585/4680 ds39625b-page 456 preliminary ? 2004 microchip technology inc. 29.1 package marking information (continued) 44-lead tqfp xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx yywwnnn example pic18f4585 -i/pt 0410017 xxxxxxxxxx 44-lead qfn xxxxxxxxxx xxxxxxxxxx yywwnnn pic18f4680 example -i/ml 0410017
? 2004 microchip technology inc. preliminary ds39625b-page 457 pic18f2585/2680/4585/4680 29.2 package details the following sections give the technical details of the packages. 28-lead skinny plastic dual in-line (sp) ? 300 mil body (pdip) 15 10 5 15 10 5 mold draft angle bottom 15 10 5 15 10 5 mold draft angle top 10.92 8.89 8.13 .430 .350 .320 eb overall row spacing 0.56 0.48 0.41 .022 .019 .016 b lower lead width 1.65 1.33 1.02 .065 .053 .040 b1 upper lead width 0.38 0.29 0.20 .015 .012 .008 c lead thickness 3.43 3.30 3.18 .135 .130 .125 l tip to seating plane 35.18 34.67 34.16 1.385 1.365 1.345 d overall length 7.49 7.24 6.99 .295 .285 .275 e1 molded package width 8.26 7.87 7.62 .325 .310 .300 e shoulder to shoulder width 0.38 .015 a1 base to seating plane 3.43 3.30 3.18 .135 .130 .125 a2 molded package thickness 4.06 3.81 3.56 .160 .150 .140 a top to seating plane 2.54 .100 p pitch 28 28 n number of pins max nom min max nom min dimension limits millimeters inches* units 2 1 d n e1 c eb e p l a2 b b1 a a1 notes: jedec equivalent: mo-095 drawing no. c04-070 * controlling parameter dimension d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. significant characteristic
pic18f2585/2680/4585/4680 ds39625b-page 458 preliminary ? 2004 microchip technology inc. 28-lead plastic small outline (so) ? wide, 300 mil body (soic) foot angle top 048048 15 12 0 15 12 0 mold draft angle bottom 15 12 0 15 12 0 mold draft angle top 0.51 0.42 0.36 .020 .017 .014 b lead width 0.33 0.28 0.23 .013 .011 .009 c lead thickness 1.27 0.84 0.41 .050 .033 .016 l foot length 0.74 0.50 0.25 .029 .020 .010 h chamfer distance 18.08 17.87 17.65 .712 .704 .695 d overall length 7.59 7.49 7.32 .299 .295 .288 e1 molded package width 10.67 10.34 10.01 .420 .407 .394 e overall width 0.30 0.20 0.10 .012 .008 .004 a1 standoff 2.39 2.31 2.24 .094 .091 .088 a2 molded package thickness 2.64 2.50 2.36 .104 .099 .093 a overall height 1.27 .050 p pitch 28 28 n number of pins max nom min max nom min dimension limits millimeters inches* units 2 1 d p n b e e1 l c 45 h a2 a a1 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-013 drawing no. c04-052 significant characteristic
? 2004 microchip technology inc. preliminary ds39625b-page 459 pic18f2585/2680/4585/4680 40-lead plastic dual in-line (p) ? 600 mil body (pdip) 15 10 5 15 10 5 mold draft angle bottom 15 10 5 15 10 5 mold draft angle top 17.27 16.51 15.75 .680 .650 .620 eb overall row spacing 0.56 0.46 0.36 .022 .018 .014 b lower lead width 1.78 1.27 0.76 .070 .050 .030 b1 upper lead width 0.38 0.29 0.20 .015 .012 .008 c lead thickness 3.43 3.30 3.05 .135 .130 .120 l tip to seating plane 52.45 52.26 51.94 2.065 2.058 2.045 d overall length 14.22 13.84 13.46 .560 .545 .530 e1 molded package width 15.88 15.24 15.11 .625 .600 .595 e shoulder to shoulder width 0.38 .015 a1 base to seating plane 4.06 3.81 3.56 .160 .150 .140 a2 molded package thickness 4.83 4.45 4.06 .190 .175 .160 a top to seating plane 2.54 .100 p pitch 40 40 n number of pins max nom min max nom min dimension limits millimeters inches* units a2 1 2 d n e1 c eb e p l b b1 a a1 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: mo-011 drawing no. c04-016 significant characteristic
pic18f2585/2680/4585/4680 ds39625b-page 460 preliminary ? 2004 microchip technology inc. 44-lead plastic thin quad flatpack (pt) 10x10x1 mm body, 1.0/0.10 mm lead form (tqfp) * controlling parameter notes: dimensions d1 and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per side. jedec equivalent: ms-026 drawing no. c04-076 1.14 0.89 0.64 .045 .035 .025 ch pin 1 corner chamfer 1.00 .039 (f) footprint (reference) (f) a a1 a2 e e1 #leads=n1 p b d1 d n 1 2 c l units inches millimeters* dimension limits min nom max min nom max number of pins n 44 44 pitch p .031 0.80 overall height a .039 .043 .047 1.00 1.10 1.20 molded package thickness a2 .037 .039 .041 0.95 1.00 1.05 standoff a1 .002 .004 .006 0.05 0.10 0.15 foot length l .018 .024 .030 0.45 0.60 0.75 foot angle 03.5 7 03.5 7 overall width e .463 .472 .482 11.75 12.00 12.25 overall length d .463 .472 .482 11.75 12.00 12.25 molded package width e1 .390 .394 .398 9.90 10.00 10.10 molded package length d1 .390 .394 .398 9.90 10.00 10.10 pins per side n1 11 11 lead thickness c .004 .006 .008 0.09 0.15 0.20 lead width b .012 .015 .017 0.30 0.38 0.44 mold draft angle top 51015 51015 mold draft angle bottom 51015 51015 ch x 45 significant characteristic
? 2004 microchip technology inc. preliminary ds39625b-page 461 pic18f2585/2680/4585/4680 44-lead plastic quad flat no lead package (ml) 8x8 mm body (qfn)
pic18f2585/2680/4585/4680 ds39625b-page 462 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 463 pic18f2585/2680/4585/4680 appendix a: revision history revision a (december 2003) original data sheet for pic18f2585/2680/4585/4680 devices. revision b (july 2004) this update includes updates to the electrical specifi- cations in section 27.0 and includes minor corrections to the data sheet text. appendix b: device differences the differences between the devices listed in this data sheet are shown in table b-1. table b-1: device differences features pic18f2585 pic18f2680 pic18f4585 pic18f4680 program memory (bytes) 49152 65536 49152 65536 program memory (instructions) 24576 32768 24576 32768 interrupt sources 27 27 28 28 i/o ports ports a, b, c, (e) ports a, b, c, (e) ports a, b, c, d, e ports a, b, c, d, e capture/compare/pwm modules 1 1 1 1 enhanced capture/compare/ pwm modules 001 1 parallel communications (psp) no no yes yes 10-bit analog-to-digital module 8 input channels 8 input channels 11 input channels 11 input channels packages 28-pin pdip 28-pin soic 28-pin pdip 28-pin soic 40-pin pdip 44-pin tqfp 44-pin qfn 40-pin pdip 44-pin tqfp 44-pin qfn
pic18f2585/2680/4585/4680 ds39625b-page 464 preliminary ? 2004 microchip technology inc. appendix c: conversion considerations this appendix discusses the considerations for converting from previous versions of a device to the ones listed in this data sheet. typically, these changes are due to the differences in the process technology used. an example of this type of conversion is from a pic16c74a to a pic16c74b. not applicable appendix d: migration from baseline to enhanced devices this section discusses how to migrate from a baseline device (i.e., pic16c5x) to an enhanced mcu device (i.e., pic18fxxx). the following are the list of modifications over the pic16c5x microcontroller family: not currently available
? 2004 microchip technology inc. preliminary ds39625b-page 465 pic18f2585/2680/4585/4680 appendix e: migration from mid-range to enhanced devices a detailed discussion of the differences between the mid-range mcu devices (i.e., pic16cxxx) and the enhanced devices (i.e., pic18fxxx) is provided in an716, ?migrating designs from pic16c74a/74b to pic18c442 .? the changes discussed, while device specific, are generally applicable to all mid-range to enhanced device migrations. this application note is available as literature number ds00716. appendix f: migration from high-end to enhanced devices a detailed discussion of the migration pathway and differences between the high-end mcu devices (i.e., pic17cxxx) and the enhanced devices (i.e., pic18fxxx) is provided in an726, ?pic17cxxx to pic18cxxx migration .? this application note is available as literature number ds00726.
pic18f2585/2680/4585/4680 ds39625b-page 466 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 467 pic18f2585/2680/4585/4680 index a a/d ................................................................................... 247 acquisition requirements ........................................ 252 adcon0 register .................................................... 247 adcon1 register .................................................... 247 adcon2 register .................................................... 247 adresh register ............................................ 247, 250 adresl register .................................................... 247 analog port pins, configuring .................................. 254 associated registers ............................................... 256 automatic acquisition time ...................................... 253 configuring the module ............................................ 251 conversion clock (t ad ) ........................................... 253 conversion status (go/done bit) .......................... 250 conversions ............................................................. 255 converter characteristics ........................................ 451 converter interrupt, configuring .............................. 251 operation in power managed modes ...................... 254 special event trigger (eccp1) ....................... 174, 256 use of the ccp1 trigger .......................................... 256 absolute maximum ratings ............................................. 417 ac (timing) characteristics ............................................. 433 load conditions for device timing specifications ....................................... 434 parameter symbology ............................................. 433 temperature and voltage specifications ................................................... 434 timing conditions .................................................... 434 access bank ...................................................................... 69 mapping with indexed literal offset mode ................. 93 ackstat ........................................................................ 217 ackstat status flag ..................................................... 217 adcon0 register ............................................................ 247 go/done bit ........................................................... 250 adcon1 register ............................................................ 247 adcon2 register ............................................................ 247 addfsr .......................................................................... 404 addlw ............................................................................ 367 addulnk ........................................................................ 404 addwf ............................................................................ 367 addwfc ......................................................................... 368 adresh register ............................................................ 247 adresl register .................................................... 247, 250 analog-to-digital converter. see a/d. and bsr ............................................................................. 93 andlw ............................................................................ 368 andwf ............................................................................ 369 assembler mpasm assembler .................................................. 411 auto-wake-up on sync break character ......................... 240 b bank select register (bsr) ............................................... 67 baud rate generator ....................................................... 213 baud rate generator (brg) ............................................ 231 bc .................................................................................... 369 bcf .................................................................................. 370 bf .................................................................................... 217 bf status flag ................................................................. 217 bit timing configuration registers brgcon1 ............................................................... 338 brgcon2 ............................................................... 338 brgcon3 ............................................................... 338 block diagrams a/d ........................................................................... 250 analog input model .................................................. 251 baud rate generator .............................................. 213 can buffers and protocol engine ........................... 274 capture mode operation ......................................... 166 comparator i/o operating modes ........................... 258 comparator output .................................................. 260 comparator voltage reference ............................... 264 compare mode operation ....................................... 167 device clock .............................................................. 28 enhanced pwm ....................................................... 175 eusart receive .................................................... 238 eusart transmit ................................................... 236 external power-on reset circuit (slow v dd power-up) ........................................ 43 fail-safe clock monitor ........................................... 355 generic i/o port operation ...................................... 129 high/low-voltage detect with external input .................................................. 268 mssp (i 2 c master mode) ........................................ 211 mssp (i 2 c mode) .................................................... 196 mssp (spi mode) ................................................... 187 on-chip reset circuit ................................................ 41 pic18f2585/2680 ..................................................... 10 pic18f4585/4680 ..................................................... 11 pll (hs mode) .......................................................... 25 portd and porte (parallel slave port) ............... 144 pwm operation (simplified) .................................... 169 reads from flash program memory ......................... 99 single comparator ................................................... 259 table read operation ............................................... 95 table write operation ............................................... 96 table writes to flash program memory .................. 101 timer0 in 16-bit mode ............................................. 148 timer0 in 8-bit mode ............................................... 148 timer1 ..................................................................... 152 timer1 (16-bit read/write mode) ............................ 152 timer2 ..................................................................... 158 timer3 ..................................................................... 160 timer3 (16-bit read/write mode) ............................ 160 voltage reference output buffer example ................................................ 265 watchdog timer ...................................................... 352 block diagrams comparator analog input model .............................................................. 261 bn .................................................................................... 370 bnc ................................................................................. 371 bnn ................................................................................. 371 bnov .............................................................................. 372 bnz ................................................................................. 372 bor. see brown-out reset. bov ................................................................................. 375 bra ................................................................................. 373 brg. see baud rate generator.
p ic 18f2585/2680/4585/4680 ds39625b-page 468 preliminary ? 2004 microchip technology inc. brown-out reset (bor) ..................................................... 44 detecting .................................................................... 44 disabling in sleep mode ............................................ 44 software enabled ....................................................... 44 bsf .................................................................................. 373 btfsc ............................................................................. 374 btfss .............................................................................. 374 btg .................................................................................. 375 bz ..................................................................................... 376 c c compilers mplab c17 ............................................................. 412 mplab c18 ............................................................. 412 mplab c30 ............................................................. 412 call ................................................................................ 376 callw ............................................................................. 405 capture (ccp1 module) ................................................... 165 associated registers ............................................... 168 ccp1 pin configuration ........................................... 165 software interrupt .................................................... 165 timer1/timer3 mode selection ................................ 165 capture (eccp1 module) ................................................ 174 eccpr1h:eccpr1l registers .............................. 165 capture/compare/pwm (ccp1) ...................................... 163 capture mode. see capture. ccp1 mode and timer resources .......................... 164 ccpr1h or eccpr1h register ............................. 164 ccpr1l or eccpr1l register ............................... 164 compare mode. see compare. interaction between ccp1 and eccp1 for timer resources ........................... 164 module configuration ............................................... 164 pwm mode. see pwm. clock sources .................................................................... 28 selecting the 31 khz source ...................................... 29 selection using osccon register ........................... 29 clrf ................................................................................ 377 clrwdt .......................................................................... 377 code examples 16 x 16 signed multiply routine .............................. 112 16 x 16 unsigned multiply routine .......................... 112 8 x 8 signed multiply routine .................................. 111 8 x 8 unsigned multiply routine .............................. 111 changing between capture prescalers ................... 165 changing to configuration mode ............................. 278 computed goto using an offset value ................... 64 data eeprom read ............................................... 107 data eeprom refresh routine .............................. 108 data eeprom write ............................................... 107 erasing a flash program memory row ................... 100 fast register stack .................................................... 64 how to clear ram (bank 1) using indirect addressing ............................................ 88 implementing a real-time clock using a timer1 interrupt service .................................. 155 initializing porta .................................................... 129 initializing portb .................................................... 132 initializing portc .................................................... 135 initializing portd .................................................... 138 initializing porte .................................................... 141 loading the sspbuf (sspsr) register ................. 190 reading a can message ........................................ 293 reading a flash program memory word .................. 99 saving status, wreg and bsr registers in ram .................................... 128 transmitting a can message using banked method ............................................... 286 transmitting a can message using win bits ......... 286 win and icode bits usage in interrupt service routine to access tx/rx buffers ....... 278 writing to flash program memory ................... 102?103 code protection ............................................................... 343 comf .............................................................................. 378 comparator ...................................................................... 257 analog input connection considerations ................ 261 associated registers ............................................... 261 configuration ........................................................... 258 effects of a reset .................................................... 260 interrupts ................................................................. 260 operation ................................................................. 259 operation during sleep ........................................... 260 outputs .................................................................... 259 reference ................................................................ 259 external signal ................................................ 259 internal signal .................................................. 259 response time ........................................................ 259 comparator specifications ............................................... 431 comparator voltage reference ....................................... 263 accuracy and error .................................................. 264 associated registers ............................................... 265 configuring .............................................................. 263 connection considerations ...................................... 264 effects of a reset .................................................... 264 operation during sleep ........................................... 264 compare (ccp module) special event trigger .............................................. 161 compare (ccp1 module) ................................................ 167 associated registers ............................................... 168 ccp1 pin configuration ........................................... 167 ccpr1 register ...................................................... 167 software interrupt .................................................... 167 special event trigger .............................................. 167 timer1/timer3 mode selection ................................ 167 compare (eccp module) ................................................ 174 compare (eccp1 module) special event trigger ...................................... 174, 256 configuration bits ............................................................ 343 configuration mode ......................................................... 324 configuration register protection .................................... 360 context saving during interrupts ..................................... 128 conversion considerations .............................................. 464 cpfseq .......................................................................... 378 cpfsgt .......................................................................... 379 cpfslt ........................................................................... 379 crystal oscillator/cerami c resonator ................................ 23 d data addressing modes .................................................... 88 comparing addressing modes with the extended instruction set enabled ..................... 92 direct ......................................................................... 88 indexed literal offset ................................................ 91 indirect ....................................................................... 88 inherent and literal .................................................... 88 data eeprom code protection ....................................................... 360
? 2004 microchip technology inc. preliminary ds39625b-page 469 pic18f2585/2680/4585/4680 data eeprom memory ................................................... 105 associated registers ............................................... 109 eeadr and eeadrh registers ............................. 105 eecon1 and eecon2 registers ........................... 105 operation during code-protect ............................... 108 protection against spurious write ........................... 108 reading .................................................................... 107 using ........................................................................ 108 write verify .............................................................. 107 writing ...................................................................... 107 data memory ..................................................................... 67 access bank .............................................................. 69 and the extended instruction set ............................... 91 bank select register (bsr) ....................................... 67 general purpose registers ........................................ 69 map for pic18f2x8x/4x8x ....................................... 68 special function registers ........................................ 70 daw ................................................................................. 380 dc and ac characteristics .............................................. 453 dc characteristics ........................................................... 428 power-down and supply current ............................ 420 supply voltage ......................................................... 419 dcfsnz .......................................................................... 381 decf ............................................................................... 380 decfsz ........................................................................... 381 demonstration boards picdem 1 ................................................................ 414 picdem 17 .............................................................. 415 picdem 18r ........................................................... 415 picdem 2 plus ........................................................ 414 picdem 3 ................................................................ 414 picdem 4 ................................................................ 414 picdem lin ............................................................ 415 picdem usb ........................................................... 415 picdem.net internet/ethernet ................................. 414 development support ...................................................... 411 device differences ........................................................... 463 device overview .................................................................. 7 features (table) ............................................................ 9 new core features ...................................................... 7 device reset timers .......................................................... 45 oscillator start-up timer (ost) ................................. 45 pll lock time-out ..................................................... 45 power-up timer (pwrt) ........................................... 45 direct addressing ............................................................... 89 disable mode ................................................................... 324 e ecan module .................................................................. 273 baud rate setting .................................................... 332 bit time partitioning ................................................. 332 bit timing configuration registers .......................... 338 calculating t q , nominal bit rate and nominal bit time ............................................. 335 can baud rate registers ....................................... 311 can control and status registers .......................... 275 can controller register map .................................. 319 can i/o control register ......................................... 314 can interrupt registers ........................................... 315 can interrupts ......................................................... 339 acknowledge ................................................... 341 bus activity wake-up ....................................... 341 bus-off ............................................................. 341 code bits ......................................................... 340 error ................................................................. 341 message error ................................................. 340 receive ........................................................... 340 receiver bus passive ...................................... 341 receiver overflow ........................................... 341 receiver warning ............................................ 341 transmit ........................................................... 340 transmitter bus passive .................................. 341 transmitter warning ........................................ 341 can message buffers ............................................. 326 dedicated receive .......................................... 326 dedicated transmit ......................................... 326 programmable auto-rtr ................................ 327 programmable transmit/receive .................... 326 can message transmission ................................... 327 aborting ........................................................... 327 initiating ........................................................... 327 priority ............................................................. 328 can modes of operation ........................................ 324 can registers ......................................................... 275 configuration mode ................................................. 324 dedicated can receive buffer registers ............... 287 dedicated can transmit buffer registers .............. 282 disable mode ........................................................... 324 error detection ........................................................ 338 acknowledge ................................................... 338 bit .................................................................... 338 crc ................................................................. 338 error modes and counters .............................. 338 error states ..................................................... 338 form ................................................................ 338 stuff bit ............................................................ 338 error modes state (diagram) ................................... 339 error recognition mode ........................................... 325 filter-mask truth (table) .......................................... 330 functional modes .................................................... 325 mode 0 (legacy mode) .................................... 325 mode 1 (enhanced legacy mode) .................. 325 mode 2 (enhanced fifo mode) ...................... 326 information processing time (ipt) .......................... 335 lengthening a bit period ......................................... 337 listen only mode ..................................................... 325 loopback mode ....................................................... 325 message acceptance filters and masks ......... 302, 330 message acceptance mask and filter operation ................................................ 331 message reception ................................................. 329 enhanced fifo mode ..................................... 330 priority ............................................................. 329 time-stamping ................................................ 330 normal mode ........................................................... 324 oscillator tolerance ................................................. 337 overview .................................................................. 273 phase buffer segments ........................................... 335 programmable tx/rx and auto-rtr buffers ......... 294 programming time segments ................................. 337 propagation segment .............................................. 335 sample point ........................................................... 335 shortening a bit period ............................................ 337 synchronization ....................................................... 336 hard ................................................................. 336 resynchronization ........................................... 336 rules ............................................................... 336 synchronization segment ........................................ 335 time quanta ............................................................ 335 values for icode (table) ......................................... 340
pic18f2585/2680/4585/4680 ds39625b-page 470 preliminary ? 2004 microchip technology inc. eccp1 capture and compare modes .................................. 174 standard pwm mode ............................................... 174 effect on standard pic instructions ........................... 91, 408 effects of power managed modes on various clock sources ............................................... 31 electrical characteristics .................................................. 417 enhanced capture/compare/pwm (eccp1) .................. 173 capture mode. see capture (eccp1 module). outputs and configuration ....................................... 174 pin configurations for eccp1 ................................. 174 pwm mode. see pwm (eccp1 module). timer resources ...................................................... 174 enhanced pwm mode. see pwm (eccp1 module). ...... 175 enhanced universal sy nchronous receiver transmitter (eusart). see eusart. equations a/d calculating the minimum required acquisition time ...................................... 252 a/d acquisition time ................................................ 252 a/d minimum charging time ................................... 252 errata ................................................................................... 5 error recognition mode ................................................... 324 eusart asynchronous mode ................................................ 236 associated registers, receive ........................ 239 associated registers, transmit ....................... 237 auto-wake-up on sync break .......................... 240 break character sequence .............................. 241 receiver ........................................................... 238 setting up 9-bit mode with address detect ........................................ 238 transmitter ....................................................... 236 baud rate generator (brg) associated registers ....................................... 231 auto-baud rate detect .................................... 234 baud rate error, calculating ........................... 231 baud rates, asynchronous modes .................. 232 high baud rate select (brgh bit) .................. 231 operation in power managed mode ................ 231 sampling .......................................................... 231 synchronous master mode ...................................... 242 associated registers, receive ........................ 244 associated registers, transmit ....................... 243 reception ......................................................... 244 transmission .................................................... 242 synchronous slave mode ........................................ 245 associated registers, receive ........................ 246 associated registers, transmit ............... 245, 271 reception ......................................................... 246 transmission .................................................... 245 evaluation and programming tools ................................. 415 extended instruction set addfsr .................................................................. 404 addulnk ................................................................ 404 callw ..................................................................... 405 movsf .................................................................... 405 movss .................................................................... 406 pushl ..................................................................... 406 subfsr .................................................................. 407 subulnk ................................................................ 407 external clock input ........................................................... 24 f fail-safe clock monitor ........................................... 343, 355 interrupts in power managed modes ....................... 356 por or wake-up from sleep ................................... 356 wdt during oscillator failure ................................. 355 fast register stack ........................................................... 64 firmware instructions ...................................................... 361 flash program memory ..................................................... 95 associated registers ............................................... 103 control registers ....................................................... 96 eecon1 and eecon2 ..................................... 96 tablat (table latch) register ........................ 98 tblptr (table pointer) register ...................... 98 erase sequence ...................................................... 100 erasing .................................................................... 100 operation during code-protect ............................... 103 reading ..................................................................... 99 table pointer boundaries based on operation ....................... 98 table pointer boundaries .......................................... 98 table reads and table writes .................................. 95 write sequence ....................................................... 101 writing to ................................................................ 101 protection against spurious writes ................. 103 unexpected termination ................................. 103 write verify ...................................................... 103 fscm. see fail-safe clock monitor. g goto .............................................................................. 382 h hardware multiplier .......................................................... 111 introduction .............................................................. 111 operation ................................................................. 111 performance comparison ........................................ 111 high/low-voltage detect ................................................. 267 characteristics ......................................................... 432 effects of a reset .................................................... 271 operation ................................................................. 269 during sleep .................................................... 271 start-up time ................................................... 269 typical application ................................................... 270 hlvd. see high/low-voltage detect. ............................. 267 i i/o ports ........................................................................... 129 i 2 c mode (mssp) acknowledge sequence timing .............................. 220 baud rate generator .............................................. 213 bus collision during a repeated start condition .................. 224 during a stop condition .................................. 225 clock arbitration ...................................................... 214 clock stretching ....................................................... 206 10-bit slave receive mode (sen = 1) ............ 206 10-bit slave transmit mode ............................ 206 7-bit slave receive mode (sen = 1) .............. 206 7-bit slave transmit mode .............................. 206 clock synchronization and the ckp bit (sen = 1) ............................................ 207 effect of a reset ...................................................... 221 general call address support ................................. 210
? 2004 microchip technology inc. preliminary ds39625b-page 471 pic18f2585/2680/4585/4680 i 2 c clock rate w/brg ............................................. 213 master mode ............................................................ 211 operation ......................................................... 212 reception ......................................................... 217 repeated start condition timing ..................... 216 start condition ................................................. 215 transmission ................................................... 217 transmit sequence .......................................... 212 multi-master communication, bus collision and arbitration ................................................. 221 multi-master mode ................................................... 221 operation ................................................................. 200 read/write bit information (r/w bit) ............... 200, 201 registers .................................................................. 196 serial clock (rc3/sck/scl) ................................... 201 slave mode .............................................................. 200 addressing ....................................................... 200 reception ......................................................... 201 transmission ................................................... 201 sleep operation ....................................................... 221 stop condition timing .............................................. 220 id locations ............................................................. 343, 360 incf ................................................................................. 382 incfsz ............................................................................ 383 in-circuit debugger .......................................................... 360 in-circuit serial programming (icsp) ...................... 343, 360 indexed literal offset addressing mode .......................... 408 and standard pic18 instructions ............................. 408 indexed literal offset mode ......................................... 91, 93 indirect addressing ............................................................ 89 infsnz ............................................................................ 383 initialization conditions for all registers ...................... 49?60 instruction cycle ................................................................ 65 clocking scheme ....................................................... 65 instruction flow/pipelining ................................................. 65 instruction set .................................................................. 361 addlw .................................................................... 367 addwf .................................................................... 367 addwf (indexed literal offset mode) .................... 409 addwfc ................................................................. 368 andlw .................................................................... 368 andwf .................................................................... 369 bc ............................................................................ 369 bcf .......................................................................... 370 bn ............................................................................ 370 bnc ......................................................................... 371 bnn ......................................................................... 371 bnov ....................................................................... 372 bnz .......................................................................... 372 bov ......................................................................... 375 bra .......................................................................... 373 bsf .......................................................................... 373 bsf (indexed literal offset mode) .......................... 409 btfsc ..................................................................... 374 btfss ..................................................................... 374 btg .......................................................................... 375 bz ............................................................................ 376 call ........................................................................ 376 clrf ........................................................................ 377 clrwdt .................................................................. 377 comf ...................................................................... 378 cpfseq .................................................................. 378 cpfsgt .................................................................. 379 cpfslt ................................................................... 379 daw ......................................................................... 380 dcfsnz .................................................................. 381 decf ....................................................................... 380 decfsz .................................................................. 381 extended instructions .............................................. 403 and using mplab tools ................................. 410 considerations when enabling ........................ 408 syntax ............................................................. 403 general format ....................................................... 363 goto ...................................................................... 382 incf ........................................................................ 382 incfsz .................................................................... 383 infsnz .................................................................... 383 iorlw ..................................................................... 384 iorwf ..................................................................... 384 lfsr ....................................................................... 385 movf ...................................................................... 385 movff .................................................................... 386 movlb .................................................................... 386 movlw ................................................................... 387 movwf ................................................................... 387 mullw .................................................................... 388 mulwf ................................................................... 388 negf ....................................................................... 389 nop ......................................................................... 389 pop ......................................................................... 390 push ....................................................................... 390 rcall ..................................................................... 391 reset ..................................................................... 391 retfie .................................................................... 392 retlw .................................................................... 392 return .................................................................. 393 rlcf ....................................................................... 393 rlncf ..................................................................... 394 rrcf ....................................................................... 394 rrncf .................... ................................................ 395 setf ....................................................................... 395 setf (indexed literal offset mode) ........................ 409 sleep ..................................................................... 396 standard instructions ............................................... 361 subfwb ................................................................. 396 sublw .................................................................... 397 subwf .................................................................... 397 subwfb ................................................................. 398 swapf .................................................................... 398 tblrd ..................................................................... 399 tblwt .................................................................... 400 tstfsz ................................................................... 401 xorlw ................................................................... 401 xorwf ................................................................... 402 summary table ....................................................... 364 intcon register rbif bit ................................................................... 132 intcon registers ........................................................... 115 inter-integrated circuit. see i 2 c. internal oscillator block ..................................................... 26 adjustment ................................................................. 26 intio modes ............................................................. 26 intosc output frequency ....................................... 26 osctune register ................................................... 26 internal rc oscillator use with wdt .......................................................... 352 interrupt sources ............................................................. 343 a/d conversion complete ....................................... 251 capture complete (ccp1) ...................................... 165 compare complete (ccp1) .................................... 167
pic18f2585/2680/4585/4680 ds39625b-page 472 preliminary ? 2004 microchip technology inc. ecan module .......................................................... 339 interrupt-on-change (rb7:rb4) .............................. 132 intn pin ................................................................... 128 portb, interrupt-on-change .................................. 128 tmr0 ....................................................................... 128 tmr0 overflow ........................................................ 149 tmr2 to pr2 match (pwm) ............................ 169, 175 tmr3 overflow ........................................ 151, 159, 161 interrupts .......................................................................... 113 logic (diagram) ........................................................ 114 interrupts, flag bits interrupt-on-change (rb7:rb4) flag (rbif bit) ..... 132 intosc frequency drift .................................................... 26 intosc, intrc. see internal oscillator block. iorlw ............................................................................. 384 iorwf ............................................................................. 384 ipr registers ................................................................... 124 l lfsr ................................................................................ 385 listen only mode ............................................................. 324 loopback mode ................................................................ 324 low-voltage icsp programming. see single-supply icsp programming. m master clear reset (mclr ) ............................................... 43 master synchronous serial port (mssp). see mssp. memory organization ......................................................... 61 data memory ............................................................. 67 program memory ....................................................... 61 memory programming requirements .............................. 430 migration from baseline to enhanced devices ................................................... 464 migration from high-end to enhanced devices ................................................... 465 migration from mid-range to enhanced devices ................................................... 465 movf ............................................................................... 385 movff ............................................................................. 386 movlb ............................................................................. 386 movlw ............................................................................ 387 movsf ............................................................................ 405 movss ............................................................................ 406 movwf ........................................................................... 387 mplab asm30 assembler, linker, librarian .................. 412 mplab icd 2 in-circuit debugger ................................... 413 mplab ice 2000 high-performance universal in-circuit emulator ................................... 413 mplab ice 4000 high-performance universal in-circuit emulator ................................... 413 mplab integrated development environment software .............................................. 411 mplab pm3 device programmer .................................... 413 mplink object linker/mplib object librarian ............... 412 mssp ack pulse ........................................................ 200, 201 control registers (general) ...................................... 187 i 2 c mode. see i 2 c mode. module overview ..................................................... 187 spi master/slave connection .................................. 191 spi mode. see spi mode. sspbuf ................................................................... 192 sspsr ..................................................................... 192 mullw ............................................................................ 388 mulwf ............................................................................ 388 n negf ............................................................................... 389 nop ................................................................................. 389 normal operation mode .................................................. 324 o opcode field descriptions ............................................... 362 option_reg register psa bit .................................................................... 149 t0cs bit .................................................................. 148 t0ps2:t0ps0 bits ................................................... 149 t0se bit .................................................................. 148 oscillator configuration ..................................................... 23 ec .............................................................................. 23 ecio .......................................................................... 23 hs .............................................................................. 23 hspll ....................................................................... 23 internal oscillator block ............................................. 26 intio1 ....................................................................... 23 intio2 ....................................................................... 23 lp .............................................................................. 23 rc ............................................................................. 23 rcio .......................................................................... 23 xt .............................................................................. 23 oscillator selection .......................................................... 343 oscillator start-up timer (ost) ................................... 31, 45 oscillator switching ........................................................... 28 oscillator transitions ......................................................... 29 oscillator, timer1 ............................................................. 161 oscillator, timer3 ..................................................... 151, 159 p packaging information ..................................................... 455 details ...................................................................... 457 marking .................................................................... 455 parallel slave port (psp) ......................................... 138, 144 associated registers ............................................... 145 cs (chip select) ...................................................... 144 portd .................................................................... 144 rd (read input) ....................................................... 144 select (pspmode bit) .................................... 138, 144 wr (write input) ...................................................... 144 pickit 1 flash starter kit ................................................. 415 picstart plus development programmer .................... 414 pie registers ................................................................... 121 pin functions mclr /v pp /re3 ................................................... 12, 16 osc1/clki/ra7 .................................................. 12, 16 osc2/clko/ra6 ................................................ 12, 16 ra0/an0 .................................................................... 13 ra0/an0/cv ref ........................................................ 17 ra1/an1 .............................................................. 13, 17 ra2/an2/v ref - ................................................... 13, 17 ra3/an3/v ref + .................................................. 13, 17 ra4/t0cki .......................................................... 13, 17 ra5/an4/ss /hlvdin .......................................... 13, 17 rb0/int0/an10 ......................................................... 14 rb0/int0/flt0/an10 ................................................ 18 rb1/int1/an8 ..................................................... 14, 18 rb2/int2/cantx ................................................ 14, 18 rb3/canrx ........................................................ 14, 18
? 2004 microchip technology inc. preliminary ds39625b-page 473 pic18f2585/2680/4585/4680 rb4/kbi0/an9 ..................................................... 14, 18 rb5/kbi1/pgm .................................................... 14, 18 rb6/kbi2/pgc .................................................... 14, 18 rb7/kbi3/pgd .................................................... 14, 18 rc0/t1oso/t13cki ........................................... 15, 19 rc1/t1osi .......................................................... 15, 19 rc2/ccp1 ........................................................... 15, 19 rc3/sck/scl ..................................................... 15, 19 rc4/sdi/sda ...................................................... 15, 19 rc5/sdo ............................................................. 15, 19 rc6/tx/ck .......................................................... 15, 19 rc7/rx/dt .......................................................... 15, 19 rd0/psp0/c1in+ ...................................................... 20 rd1/psp1/c1in- ....................................................... 20 rd2/psp2/c2in+ ...................................................... 20 rd3/psp3/c2in- ....................................................... 20 rd4/psp4/eccp1/p1a ............................................. 20 rd5/psp5/p1b .......................................................... 20 rd6/psp6/p1c .......................................................... 20 rd7/psp7/p1d .......................................................... 20 re0/rd /an5 .............................................................. 21 re1/wr /an6/c1out ................................................ 21 re2/cs /an7/c2out ................................................. 21 v dd ...................................................................... 15, 21 v ss ....................................................................... 15, 21 pinout i/o descriptions pic18f2585/2680 ...................................................... 12 pic18f4585/4680 ...................................................... 16 pir registers ................................................................... 118 pll use with intosc ....................................................... 25 pll frequency multiplier ................................................... 25 hspll oscillator mode .............................................. 25 in intosc modes ...................................................... 26 pll lock time-out ............................................................. 45 pop ................................................................................. 390 por. see power-on reset. porta associated registers ............................................... 131 i/o summary ............................................................ 130 lata register .......................................................... 129 porta register ...................................................... 129 trisa register ........................................................ 129 portb associated registers ............................................... 134 i/o summary ............................................................ 133 latb register .......................................................... 132 portb register ...................................................... 132 rb7:rb4 interrupt-on-change flag (rbif bit) ......................................................... 132 trisb register ........................................................ 132 portc associated registers ............................................... 137 i/o summary ............................................................ 136 latc register ......................................................... 135 portc register ...................................................... 135 rc3/sck/scl pin ................................................... 201 trisc register ........................................................ 135 portd associated registers ............................................... 140 i/o summary ............................................................ 139 latd register ......................................................... 138 parallel slave port (psp) function .......................... 138 portd register ...................................................... 138 trisd register ........................................................ 138 porte associated registers ............................................... 143 i/o summary ........................................................... 143 late register ......................................................... 141 porte register ...................................................... 141 psp mode select (pspmode bit) .......................... 138 trise register ........................................................ 141 postscaler, wdt assignment (psa bit) .............................................. 149 rate select (t0ps2:t0ps0 bits) ............................. 149 switching between timer0 and wdt ...................... 149 power managed modes ..................................................... 33 and a/d operation ................................................... 254 and eusart operation .......................................... 231 and multiple sleep commands .................................. 34 clock sources ........................................................... 33 clock transitions and status indicators .................... 34 effects on clock sources .......................................... 31 entering ..................................................................... 33 exiting idle and sleep modes .................................... 39 by interrupt ........................................................ 39 by reset ............................................................ 39 by wdt time-out .............................................. 39 without an oscillator start-up delay ................. 40 idle modes ................................................................. 37 pri_idle .......................................................... 38 rc_idle ........................................................... 39 sec_idle ......................................................... 38 run modes ................................................................ 34 pri_run ........................................................... 34 rc_run ............................................................ 35 sec_run ......................................................... 34 selecting .................................................................... 33 sleep mode ............................................................... 37 summary (table) ........................................................ 33 power-on reset (por) ...................................................... 43 oscillator start-up timer (ost) ................................. 45 power-up timer (pwrt) ........................................... 45 time-out sequence ................................................... 45 power-up delays ............................................................... 31 power-up timer (pwrt) ............................................. 31, 45 prescaler timer2 ..................................................................... 176 prescaler, capture ........................................................... 165 prescaler, timer0 ............................................................ 149 assignment (psa bit) .............................................. 149 rate select (t0ps2:t0ps0 bits) ............................. 149 switching between timer0 and wdt ...................... 149 prescaler, timer2 ............................................................ 170 pri_idle mode ................................................................. 38 pri_run mode ................................................................. 34 pro mate ii universal device programmer .................. 413 program counter ............................................................... 62 pcl, pch and pcu registers .................................. 62 pclath and pclatu registers .............................. 62 program memory and the extended instruction set .............................. 91 code protection ....................................................... 358 instructions ................................................................ 66 two-word .......................................................... 66 interrupt vector .......................................................... 61 look-up tables .......................................................... 64 map and stack (diagram) .......................................... 61 reset vector .............................................................. 61
pic18f2585/2680/4585/4680 ds39625b-page 474 preliminary ? 2004 microchip technology inc. program verification and code protection ....................... 357 associated registers ............................................... 357 programming, device instructions ................................... 361 psp. see parallel slave port. pulse-width modulation. see pwm (ccp1 module) and pwm (eccp1 module). push ............................................................................... 390 push and pop instructions .............................................. 63 pushl ............................................................................. 406 pwm (ccp1 module) ....................................................... 169 associated registers ............................................... 171 duty cycle ................................................................ 169 eccpr1h:eccpr1l registers .............................. 169 example frequencies/resolutions .......................... 170 period ....................................................................... 169 setup for pwm operation ........................................ 170 tmr2 to pr2 match ................................................ 169 pwm (eccp1 module) .................................................... 175 associated registers ............................................... 186 auto-shutdown ........................................................ 170 direction change in full-bridge output mode .................................................... 180 duty cycle ................................................................ 176 eccpr1h:eccpr1l registers .............................. 175 effects of a reset ..................................................... 185 enhanced pwm auto-shutdown ............................. 182 example frequencies/resolutions .......................... 176 full-bridge application example .............................. 180 full-bridge mode ...................................................... 179 half-bridge mode ..................................................... 178 half-bridge output mode applications example ....................................... 178 output configurations .............................................. 176 output relationships (active-high) .......................... 177 output relationships (active-low) ........................... 177 period ....................................................................... 175 programmable dead-band delay ............................ 182 setup ........................................................................ 185 start-up considerations ........................................... 184 tmr2 to pr2 match ................................................ 175 q q clock .................................................................... 170, 176 r ram. see data memory. rc oscillator ...................................................................... 25 rcio oscillator mode ................................................ 25 rc_idle mode .................................................................. 39 rc_run mode .................................................................. 35 rcall .............................................................................. 391 rcon register bit status during initialization .................................... 48 register file ....................................................................... 69 register file summary ................................................. 76?86 registers adcon0 (a/d control 0) ......................................... 247 adcon1 (a/d control 1) ......................................... 248 adcon2 (a/d control 2) ......................................... 249 baudcon (baud rate control) .............................. 230 bie0 (buffer interrupt enable 0) ............................... 318 bncon (tx/rx buffer n control, receive mode) ................................................. 294 bncon (tx/rx buffer n control, transmit mode) ................................................ 295 bndlc (tx/rx buffer n data length code in receive mode) ............................................. 300 bndlc (tx/rx buffer n data length code in transmit mode) ............................................ 301 bndm (tx/rx buffer n data field byte m in receive mode) ............................................. 299 bndm (tx/rx buffer n data field byte m in transmit mode) ............................................ 299 bneidh (tx/rx buffer n extended identifier, high byte in receive mode) ............................ 298 bneidh (tx/rx buffer n extended identifier, high byte in transmit mode) ........................... 298 bneidl (tx/rx buffer n extended identifier, low byte in receive mode) ............................. 298 bneidl (tx/rx buffer n extended identifier, low byte in transmit mode) ............................ 299 bnsidh (tx/rx buffer n standard identifier, high byte in receive mode) ............................ 296 bnsidh (tx/rx buffer n standard identifier, high byte in transmit mode) ........................... 296 bnsidl (tx/rx buffer n standard identifier, low byte in receive mode) ............................. 297 bnsidl (tx/rx buffer n standard identifier, low byte in transmit mode) ............................ 297 brgcon1 (baud rate control 1) ........................... 311 brgcon2 (baud rate control 2) ........................... 312 brgcon3 (baud rate control 3) ........................... 313 bsel0 (buffer select 0) ........................................... 301 cancon (can control) .......................................... 276 canstat (can status) .......................................... 277 ccp1con (capture/compare/pwm control) ................... 163 ciocon (can i/o control) ..................................... 314 cmcon (comparator control) ................................ 257 comstat (can communication status) ............... 281 config1h (configuration 1 high) .......................... 344 config2h (configuration 2 high) .......................... 346 config2l (configuration 2 low) ........................... 345 config3h (configuration 3 high) .......................... 347 config4l (configuration 4 low) ........................... 347 config5h (configuration 5 high) .......................... 348 config5l (configuration 5 low) ........................... 348 config6h (configuration 6 high) .......................... 349 config6l (configuration 6 low) ........................... 349 config7h (configuration 7 high) .......................... 350 config7l (configuration 7 low) ........................... 350 cvrcon (comparator voltage reference control) .......................................... 263 device id register 1 ................................................ 351 device id register 2 ................................................ 351 ecancon (enhanced can control) ...................... 280 eccp1as (eccp1 auto-shutdown control) .......... 183 eccp1con (enhanced capture/compare/pwm control) .................... 173 eccp1del (pwm configuration) ........................... 182 eecon1 (data eeprom control 1) ................. 97, 106 hlvdcon (hlvd control) ...................................... 267 intcon (interrupt control) ...................................... 115 intcon2 (interrupt control 2) ................................. 116 intcon3 (interrupt control 3) ................................. 117 ipr1 (peripheral interrupt priority 1) ....................... 124 ipr2 (peripheral interrupt priority 2) ....................... 125 ipr3 (peripheral interrupt priority 3) ............... 126, 317 msel0 (mask select 0) ........................................... 307 msel1 (mask select 1) ........................................... 308
? 2004 microchip technology inc. preliminary ds39625b-page 475 pic18f2585/2680/4585/4680 msel2 (mask select 2) ........................................... 309 msel3 (mask select 3) ........................................... 310 osccon (oscillator control) .................................... 30 osctune (oscillator tuning) ................................... 27 pie1 (peripheral interrupt enable 1) ........................ 121 pie2 (peripheral interrupt enable 2) ........................ 122 pie3 (peripheral interrupt enable 3) ................ 123, 316 pir1 (peripheral interrupt request (flag) 1) ............................................. 118 pir2 (peripheral interrupt request (flag) 2) ............................................. 119 pir3 (peripheral interrupt request (flag) 3) ..................................... 120, 315 rcon (reset control) ....................................... 42, 127 rcsta (receive status and control) ...................... 229 rxb0con (receive buffer 0 control) ..................... 287 rxb1con (receive buffer 1 control) ..................... 289 rxbndlc (receive buffer n data length code) .......................................... 292 rxbndm (receive buffer n data field byte m) ........................................... 292 rxbneidh (receive buffer n extended identifier, high byte) ........................................ 291 rxbneidl (receive buffer n extended identifier, low byte) ......................................... 291 rxbnsidh (receive buffer n standard identifier, high byte) ........................................ 290 rxbnsidl (receive buffer n standard identifier, low byte) ......................................... 291 rxerrcnt (receive error count) ......................... 293 rxfbconn (receive filter buffer control n) .............................................. 306 rxfconn (receive filter control n) ....................... 305 rxfneidh (receive acceptance filter n extended identifier, high byte) ........................ 303 rxfneidl (receive acceptance filter n extended identifier, low byte) ......................... 303 rxfnsidh (receive acceptance filter n standard identifier filter, high byte) ................ 302 rxfnsidl (receive acceptance filter n standard identifier filter, low byte) ................ 302 rxmneidh (receive acceptance mask n extended identifier mask, high byte) .............. 304 rxmneidl (receive acceptance mask n extended identifier mask, low byte) ............... 304 rxmnsidh (receive acceptance mask n standard identifier mask, high byte) ............... 303 rxmnsidl (receive acceptance mask n standard identifier mask, low byte) ................ 304 sdflc (standard data bytes filter length count) ......................................... 305 sspcon1 (mssp control 1, i 2 c mode) ................. 198 sspcon1 (mssp control 1, spi mode) ................. 189 sspcon2 (mssp control 2, i 2 c mode) ................. 199 sspstat (mssp status, i 2 c mode) ....................... 197 sspstat (mssp status, spi mode) ...................... 188 status ......................................................................... 87 stkptr (stack pointer) ............................................ 63 t0con (timer0 control) .......................................... 147 t1con (timer 1 control) ......................................... 151 t2con (timer 2 control) ......................................... 157 t3con (timer3 control) .......................................... 159 trise (porte/psp control) .................................. 142 txbie (transmit buffers interrupt enable) .............. 318 txbncon (transmit buffer n control) .................... 282 txbndlc (transmit buffer n data length code) .......................................... 285 txbndm (transmit buffer n data field byte m) ........................................... 284 txbneidh (transmit buffer n extended identifier, high byte) ........................................ 283 txbneidl (transmit buffer n extended identifier, low byte) ......................................... 284 txbnsidh (transmit buffer n standard identifier, high byte) ........................................ 283 txbnsidl (transmit buffer n standard identifier, low byte) ......................................... 283 txerrcnt (transmit error count) ........................ 285 txsta (transmit status and control) ..................... 228 wdtcon (watchdog timer control) ...................... 353 reset ............................................................................. 391 resets ....................................................................... 41, 343 brown-out reset (bor) ........................................... 343 oscillator start-up timer (ost) ............................... 343 power-on reset (por) ............................................ 343 power-up timer (pwrt) ......................................... 343 retfie ............................................................................ 392 retlw ............................................................................ 392 return .......................................................................... 393 return address stack ........................................................ 62 and associated registers .......................................... 62 return stack pointer (stkptr) ........................................ 63 revision history ............................................................... 463 rlcf ............................................................................... 393 rlncf ............................................................................. 394 rrcf ............................................................................... 394 rrncf ..................................... ....................................... 395 s sck ................................................................................. 187 sdi ................................................................................... 187 sdo ................................................................................. 187 sec_idle mode ............................................................... 38 sec_run mode ................................................................ 34 serial clock, sck ............................................................ 187 serial data in (sdi) .......................................................... 187 serial data out (sdo) ..................................................... 187 serial peripheral interface. see spi mode. setf ............................................................................... 395 slave select (ss ) ............................................................. 187 sleep ............................................................................. 396 sleep osc1 and osc2 pin states ...................................... 31 software simulator (mplab sim) ................................... 412 software simulator (mplab sim30) ............................... 412 special event trigger. see compare (eccp1 mode). special event trigger. see compare (eccp1 module). special features of the cpu ........................................... 343 special function registers ................................................ 70 map ...................................................................... 70?75 spi mode (mssp) associated registers ............................................... 195 bus mode compatibility ........................................... 195 effects of a reset .................................................... 195 enabling spi i/o ...................................................... 191 master mode ............................................................ 192 master/slave connection ........................................ 191 operation ................................................................. 190
pic18f2585/2680/4585/4680 ds39625b-page 476 preliminary ? 2004 microchip technology inc. operation in power managed modes ...................... 195 serial clock .............................................................. 187 serial data in ........................................................... 187 serial data out ........................................................ 187 slave mode .............................................................. 193 slave select ............................................................. 187 slave select synchronization .................................. 193 spi clock ................................................................. 192 typical connection .................................................. 191 ss .................................................................................... 187 sspov ............................................................................. 217 sspov status flag .......................................................... 217 sspstat register r/w bit ............................................................. 200, 201 stack full/underflow resets .............................................. 64 status register ................................................................... 87 subfsr ........................................................................... 407 subfwb .......................................................................... 396 sublw ............................................................................ 397 subulnk ........................................................................ 407 subwf ............................................................................ 397 subwfb .......................................................................... 398 swapf ............................................................................ 398 t table pointer operations (table) ........................................ 98 table reads/table writes .................................................. 64 tblrd ............................................................................. 399 tblwt ............................................................................. 400 time-out in various situations (table) ................................ 45 timer0 .............................................................................. 147 associated registers ............................................... 149 clock source edge select (t0se bit) ...................... 148 clock source select (t0cs bit) ............................... 148 operation ................................................................. 148 overflow interrupt .................................................... 149 prescaler. see prescaler, timer0. reads and writes in 16-bit mode ............................ 148 timer1 .............................................................................. 151 16-bit read/write mode ........................................... 153 associated registers ............................................... 155 interrupt .................................................................... 154 operation ................................................................. 152 oscillator .................................................................. 153 layout considerations ..................................... 154 resetting, using a special event trigger output (ccp) ................................................... 154 special event trigger (eccp1) ............................... 174 use as a real-time clock ....................................... 154 timer2 .............................................................................. 157 associated registers ............................................... 158 interrupt .................................................................... 158 operation ................................................................. 157 output ...................................................................... 158 pr2 register .................................................... 169, 175 tmr2 to pr2 match interrupt .......................... 169, 175 timer3 .............................................................................. 159 16-bit read/write mode ........................................... 161 associated registers ............................................... 161 operation ................................................................. 160 oscillator .................................................. 151, 159, 161 overflow interrupt .................................... 151, 159, 161 special event trigger (ccp) .................................... 161 tmr3h register .............................................. 151, 159 tmr3l register ............................................... 151, 159 timing diagrams a/d conversion ........................................................ 452 acknowledge sequence .......................................... 220 asynchronous reception ......................................... 239 asynchronous transmission .................................... 237 asynchronous transmission (back to back) ................................................. 237 automatic baud rate calculation ............................ 235 auto-wake-up bit (wue) during normal operation ............................................ 240 auto-wake-up bit (wue) during sleep ................... 240 baud rate generator with clock arbitration ............ 214 brg overflow sequence ......................................... 235 brg reset due to sda arbitration during start condition ..................................... 223 brown-out reset (bor) ........................................... 438 bus collision during a repeated start condition (case 1) ........................................... 224 bus collision during a repeated start condition (case 2) ........................................... 224 bus collision during a start condition (scl = 0) ......................................................... 223 bus collision during a start condition (sda only) ...................................................... 222 bus collision during a stop condition (case 1) ........................................................... 225 bus collision during a stop condition (case 2) ........................................................... 225 bus collision for transmit and acknowledge .......... 221 capture/compare/pwm (ccp) ............................... 440 clko and i/o .......................................................... 437 clock synchronization ............................................. 207 clock/instruction cycle .............................................. 65 eusart synchronous receive (master/slave) ................................................. 450 eusart synchronous transmission (master/slave) ................................................. 450 example spi master mode (cke = 0) ..................... 442 example spi master mode (cke = 1) ..................... 443 example spi slave mode (cke = 0) ....................... 444 example spi slave mode (cke = 1) ....................... 445 external clock (all modes except pll) ................... 435 fail-safe clock monitor ........................................... 356 first start bit timing ................................................ 215 full-bridge pwm output .......................................... 179 half-bridge pwm output ......................................... 178 high/low-voltage detect ......................................... 270 i 2 c bus data ............................................................ 446 i 2 c bus start/stop bits ............................................ 446 i 2 c master mode (7 or 10-bit transmission) ........... 218 i 2 c master mode (7-bit reception) .......................... 219 i 2 c slave mode (10-bit reception, sen = 0) .......................................................... 204 i 2 c slave mode (10-bit reception, sen = 1) .......................................................... 209 i 2 c slave mode (10-bit transmission) .................... 205 i 2 c slave mode (7-bit reception, sen = 0) ............ 202 i 2 c slave mode (7-bit reception, sen = 1) ............ 208 i 2 c slave mode (7-bit transmission) ...................... 203 i 2 c slave mode general call address sequence (7 or 10-bit addr ess mode) ............ 210 master ssp i 2 c bus data ........................................ 448 master ssp i 2 c bus start/stop bits ........................ 448 parallel slave port (pic18f4585/4680) ................... 441 parallel slave port (psp) read ............................... 145
? 2004 microchip technology inc. preliminary ds39625b-page 477 pic18f2585/2680/4585/4680 parallel slave port (psp) write ............................... 145 pwm auto-shutdown (prsen = 0, auto-restart disabled) .................................... 184 pwm auto-shutdown (prsen = 1, auto-restart enabled) ..................................... 184 pwm direction change ........................................... 181 pwm direction change at near 100% duty cycle ............................................. 181 pwm output ............................................................ 169 repeat start condition ............................................. 216 reset, watchdog timer (wdt), oscillator start-up timer (ost) and power-up timer (pwrt) ................................. 438 send break character sequence ............................ 241 slave synchronization ............................................. 193 slow rise time (mclr tied to v dd , v dd rise > t pwrt ) ............................................ 47 spi mode (master mode) ......................................... 192 spi mode (slave mode with cke = 0) ..................... 194 spi mode (slave mode with cke = 1) ..................... 194 stop condition receive or transmit mode .............. 220 synchronous reception (master mode, sren) ..................................... 244 synchronous transmission ...................................... 242 synchronous transmission (through txen) .......... 243 time-out sequence on por w/pll enabled (mclr tied to v dd ) ............................. 47 time-out sequence on power-up (mclr not tied to v dd ), case 1 ....................... 46 time-out sequence on power-up (mclr not tied to v dd ), case 2 ....................... 46 time-out sequence on power-up (mclr tied to v dd , v dd rise t pwrt ) .............. 46 timer0 and timer1 external clock .......................... 439 transition for entry to idle mode ................................ 38 transition for entry to sec_run mode .................... 35 transition for entry to sleep mode ............................ 37 transition for two-speed start-up (intosc to hspll) ........................................ 354 transition for wake from idle to run mode ............... 38 transition for wake from sleep (hspll) ................... 37 transition from rc_run mode to pri_run mode ................................................. 36 transition from sec_run mode to pri_run mode (hspll) .................................. 35 transition to rc_run mode ..................................... 36 timing diagrams and specifications ................................ 435 a/d conversion requirements ................................ 452 ac characteristics internal rc accuracy ....................................... 436 capture/compare/pwm requirements ................... 440 clko and i/o requirements ................................... 437 eusart synchronous receive requirements .................................................. 450 eusart synchronous transmission requirements .................................................. 450 example spi mode requirements master mode, cke = 0 .................................... 442 master mode, cke = 1 .................................... 443 slave mode, cke = 0 ...................................... 444 slave mode, cke = 1 ...................................... 445 external clock requirements .................................. 435 high/low-voltage detect characteristics ................ 432 i 2 c bus data requirements (slave mode) .............. 447 master ssp i 2 c bus data requirements ................ 449 master ssp i 2 c bus start/stop bits requirements ........................................... 448 parallel slave port requirements (pic18f4585/4680) ......................................... 441 pll clock ................................................................ 436 reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements ...................... 438 timer0 and timer1 external clock requirements ........................................ 439 top-of-stack access .......................................................... 62 trise register pspmode bit ......................................................... 138 tstfsz ........................................................................... 401 two-speed start-up ................................................. 343, 354 two-word instructions example cases ......................................................... 66 txsta register brgh bit ................................................................. 231 v voltage reference specifications .................................... 431 w watchdog timer (wdt) ........................................... 343, 352 associated registers ............................................... 353 control register ....................................................... 352 during oscillator failure .......................................... 355 programming considerations .................................. 352 wcol ...................................................... 215, 216, 217, 220 wcol status flag ................................... 215, 216, 217, 220 www, on-line support ................... ................................... 5 x xorlw ........................................................................... 401 xorwf ........................................................................... 402
pic18f2585/2680/4585/4680 ds39625b-page 478 preliminary ? 2004 microchip technology inc. notes:
? 2004 microchip technology inc. preliminary ds39625b-page 479 pic18f2585/2680/4585/4680 on-line support microchip provides on-line support on the microchip world wide web site. the web site is used by microchip as a means to make files and information easily available to customers. to view the site, the user must have access to the internet and a web browser, such as netscape ? or microsoft ? internet explorer. files are also available for ftp download from our ftp site. connecting to the microchip internet web site the microchip web site is available at the following url: www.microchip.com the file transfer site is available by using an ftp service to connect to: ftp://ftp.microchip.com the web site and file transfer site provide a variety of services. users may download files for the latest development tools, data sheets, application notes, user?s guides, articles and sample programs. a vari- ety of microchip specific business information is also available, including listings of microchip sales offices, distributors and factory representatives. other data available for consideration is:  latest microchip press releases  technical support section with frequently asked questions  design tips  device errata  job postings  microchip consultant program member listing  links to other useful web sites related to microchip products  conferences for products, development systems, technical information and more  listing of seminars and events systems information and upgrade hot line the systems information and upgrade line provides system users a listing of the latest versions of all of microchip?s development systems software products. plus, this line provides information on how customers can receive the most current upgrade kits. the hot line numbers are: 1-800-755-2345 for u.s. and most of canada and 1-480-792-7302 for the rest of the world. 042003
pic18f2585/2680/4585/4680 ds39625b-page 480 preliminary ? 2004 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip prod- uct. if you wish to provide your comments on organization, clarity, subject matter and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information and use this outline to provide us with your comments about this document. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds39625b pic18f2585/2680/4585/4680 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2004 microchip technology inc. preliminary ds39625b-page 481 pic18f2585/2680/4585/4680 pic18f2585/2680/4585/4680 product identification system to order or obtain information, e. g., on pricing or delivery, refer to the factory or the listed sales office . part no. x /xx xxx pattern package temperature range device device pic18f2585/2680 (1) , pic18f4585/4680 (1) , pic18f2585/2680t (2) , pic18f4585/4680t (2) ; v dd range 4.2v to 5.5v pic18lf2585/2680 (1) , pic18lf4585/4680 (1) , pic18lf2585/2680t (2) , pic18lf4585/4680t (2) ; v dd range 2.0v to 5.5v temperature range i = -40 c to +85 c (industrial) e= -40 c to +125 c (extended) package pt = tqfp (thin quad flatpack) so = soic sp = skinny plastic dip p=pdip ml = qfn pattern qtp, sqtp, code or special requirements (blank otherwise) examples: a) pic18lf4680-i/p 301 = industrial temp., pdip package, extended v dd limits, qtp pattern #301. b) pic18lf2585-i/so = industrial temp., soic package, extended v dd limits. c) pic18f4585-i/p = industrial temp., pdip package, normal v dd limits. note 1: f = standard voltage range lf = wide voltage range 2: t = in tape and reel plcc and tqfp packages only.
ds39625b-page 482 preliminary ? 2004 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: 480-792-7627 web address: www.microchip.com atlanta 3780 mansell road, suite 130 alpharetta, ga 30022 tel: 770-640-0034 fax: 770-640-0307 boston 2 lan drive, suite 120 westford, ma 01886 tel: 978-692-3848 fax: 978-692-3821 chicago 333 pierce road, suite 180 itasca, il 60143 tel: 630-285-0071 fax: 630-285-0075 dallas 16200 addison road, suite 255 addison plaza addison, tx 75001 tel: 972-818-7423 fax: 972-818-2924 detroit tri-atria office building 32255 northwestern highway, suite 190 farmington hills, mi 48334 tel: 248-538-2250 fax: 248-538-2260 kokomo 2767 s. albright road kokomo, in 46902 tel: 765-864-8360 fax: 765-864-8387 los angeles 25950 acero st., suite 200 mission viejo, ca 92691 tel: 949-462-9523 fax: 949-462-9608 san jose 1300 terra bella avenue mountain view, ca 94043 tel: 650-215-1444 fax: 650-961-0286 toronto 6285 northam drive, suite 108 mississauga, ontario l4v 1x5, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific australia microchip technology australia pty ltd unit 32 41 rawson street epping 2121, nsw sydney, australia tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing unit 706b wan tai bei hai bldg. no. 6 chaoyangmen bei str. beijing, 100027, china tel: 86-10-85282100 fax: 86-10-85282104 china - chengdu rm. 2401-2402, 24th floor, ming xing financial tower no. 88 tidu street chengdu 610016, china tel: 86-28-86766200 fax: 86-28-86766599 china - fuzhou unit 28f, world trade plaza no. 71 wusi road fuzhou 350001, china tel: 86-591-7503506 fax: 86-591-7503521 china - hong kong sar unit 901-6, tower 2, metroplaza 223 hing fong road kwai fong, n.t., hong kong tel: 852-2401-1200 fax: 852-2401-3431 china - shanghai room 701, bldg. b far east international plaza no. 317 xian xia road shanghai, 200051 tel: 86-21-6275-5700 fax: 86-21-6275-5060 china - shenzhen rm. 1812, 18/f, building a, united plaza no. 5022 binhe road, futian district shenzhen 518033, china tel: 86-755-82901380 fax: 86-755-8295-1393 china - shunde room 401, hongjian building, no. 2 fengxiangnan road, ronggui town, shunde district, foshan city, guangdong 528303, china tel: 86-757-28395507 fax: 86-757-28395571 china - qingdao rm. b505a, fullhope plaza, no. 12 hong kong central rd. qingdao 266071, china tel: 86-532-5027355 fax: 86-532-5027205 india divyasree chambers 1 floor, wing a (a3/a4) no. 11, o?shaugnessey road bangalore, 560 025, india tel: 91-80-22290061 fax: 91-80-22290062 japan yusen shin yokohama building 10f 3-17-2, shin yokohama, kohoku-ku, yokohama, kanagawa, 222-0033, japan tel: 81-45-471- 6166 fax: 81-45-471-6122 korea 168-1, youngbo bldg. 3 floor samsung-dong, kangnam-ku seoul, korea 135-882 tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 singapore 200 middle road #07-02 prime centre singapore, 188980 tel: 65-6334-8870 fax: 65-6334-8850 taiwan kaohsiung branch 30f - 1 no. 8 min chuan 2nd road kaohsiung 806, taiwan tel: 886-7-536-4816 fax: 886-7-536-4817 taiwan taiwan branch 11f-3, no. 207 tung hua north road taipei, 105, taiwan tel: 886-2-2717-7175 fax: 886-2-2545-0139 taiwan taiwan branch 13f-3, no. 295, sec. 2, kung fu road hsinchu city 300, taiwan tel: 886-3-572-9526 fax: 886-3-572-6459 europe austria durisolstrasse 2 a-4600 wels austria tel: 43-7242-2244-399 fax: 43-7242-2244-393 denmark regus business centre lautrup hoj 1-3 ballerup dk-2750 denmark tel: 45-4420-9895 fax: 45-4420-9910 france parc d?activite du moulin de massy 43 rue du saule trapu batiment a - ler etage 91300 massy, france tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany steinheilstrasse 10 d-85737 ismaning, germany tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy via salvatore quasimodo, 12 20025 legnano (mi) milan, italy tel: 39-0331-742611 fax: 39-0331-466781 netherlands waegenburghtplein 4 nl-5152 jr, drunen, netherlands tel: 31-416-690399 fax: 31-416-690340 united kingdom 505 eskdale road winnersh triangle wokingham berkshire, england rg41 5tu tel: 44-118-921-5869 fax: 44-118-921-5820 07/12/04 w orldwide s ales and s ervice


▲Up To Search▲   

 
Price & Availability of PIC18F4585-P

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X